新聞中心

EEPW首頁(yè) > 手機(jī)與無(wú)線通信 > 設(shè)計(jì)應(yīng)用 > 基于dsPIC33FJ128MC506的CAN通信(07-100)

基于dsPIC33FJ128MC506的CAN通信(07-100)

——
作者:山東省科學(xué)院自動(dòng)化研究所 張?jiān)?李明強(qiáng) 莊汝科 時(shí)間:2009-03-04 來(lái)源:電子產(chǎn)品世界 收藏

  寫報(bào)文內(nèi)容

本文引用地址:http://2s4d.com/article/92042.htm

  /*下面的函數(shù)將待發(fā)報(bào)文內(nèi)容寫入到發(fā)射緩沖區(qū),各參數(shù)含義如下:

  buf -> 發(fā)射緩沖器號(hào)

  dataLength -> 數(shù)據(jù)的長(zhǎng)度

  data1/data2/data3/data4 -> 發(fā)射數(shù)據(jù)內(nèi)容*/

  void ecan1WriteTxMsgBufData(unsigned int buf, unsigned int dataLength, unsigned int data1, unsigned int data2, unsigned int data3, unsigned int data4)

  {

  ecan1msgBuf[buf][2] = ((ecan1msgBuf[buf][2] & 0xFFF0) + dataLength) ;//數(shù)據(jù)長(zhǎng)度

  ecan1msgBuf[buf][3] = data1; //數(shù)據(jù)1

  ecan1msgBuf[buf][4] = data2; //數(shù)據(jù)2

  ecan1msgBuf[buf][5] = data3; //數(shù)據(jù)3

  ecan1msgBuf[buf][6] = data4; //數(shù)據(jù)4

  }

  報(bào)文的接收

  報(bào)文接收在中斷中進(jìn)行,函數(shù)語(yǔ)句如下:

  void __attribute__((interrupt, no_auto_psv))_C1Interrupt(void) //1中斷

  {

  IFS2bits.C1IF = 0; //請(qǐng)中斷標(biāo)志

  if(C1INTFbits.TBIF) //是否為發(fā)射中斷

  {

  C1INTFbits.TBIF = 0;

  }

  if(C1INTFbits.RBIF) //是否為接收中斷

  {

  C1INTFbits.RBIF = 0; //請(qǐng)接收中斷標(biāo)志位

  /*讀出報(bào)文*/

  ReceiveMessageID = (ecan1msgBuf[2][0]>>2);

  ReveiveDataLength = (ecan1msgBuf[2][2]&0x000f);

  ReceiveData[0] = ecan1msgBuf[2][3];

  ReceiveData[1] = ecan1msgBuf[2][4];

  ReceiveData[2] = ecan1msgBuf[2][5];

  ReceiveData[3] = ecan1msgBuf[2][6];

  C1RXFUL1bits.RXFUL2 = 0; //清報(bào)文溢出標(biāo)志

  ReceiveNewMessage = 1; //接收標(biāo)志置位

  }

  C1RXOVF1bits.RXOVF2 = 0;

  }



關(guān)鍵詞: CAN TJA1054 dsPIC33FJ128MC506

評(píng)論


技術(shù)專區(qū)

關(guān)閉