Hi,
I am working on CAN in KEA-128.I wrote a scratch code for CAN transmit.Please tell me what mistake i have done in it as it is not working.Please tell changes in my code and i don't want drivers for it.I want a simple sample code like mine here.Thanks in advance
#include "derivative.h" /* include peripheral declarations */
#include "ATHER_GPIO.h"
#include "typedefs.h"
#include "CLK.h"
UINT8 tx_select, backup_txbuffer;
void MSCAN_init();
int main(void)
{
Clk_Init(); //20Mhz frequency
MSCAN_init();
while ((MSCAN_CANCTL1&0x00) != 0); /**** wait for normal board *******/
/**** selection of transmit buffer ****/
if (MSCAN_CANTFLG != 1); /* Is Transmit Buffer full?? */
/************* select one among 3 buffers *************/
tx_select = MSCAN_CANTFLG; /* read transmit flag */
MSCAN_CANTBSEL = tx_select; /* write the value back to Can select register */
backup_txbuffer = MSCAN_CANTBSEL;
/************ Fill the parts of CAN frame(Frame ID, local priority, datalength, data) ************/
MSCAN_TSIDR0 = 0x01; /* frame id */ // standard frame has 2 registers involved
MSCAN_TEIDR0 = 0X01;
MSCAN_TDLR = 1; /* Data frame length */
MSCAN_TEDSR0 = 0X20; /*putting data into the data buffer*/
MSCAN_TBPR = backup_txbuffer; /* local priority */
MSCAN_CANTFLG = backup_txbuffer; /*start transmission */ // setting the ttransmit flasg to release the buffer
for(;;) {
}
return 0;
}
void MSCAN_init(){
SIM_PINSEL1 &= ~SIM_PINSEL1_MSCANPS_MASK; /* Selected PTC7 and PTC6 ******/
SIM_SCGC |= SIM_SCGC_MSCAN_MASK ; /* Clock enabled to CAN *******/
MSCAN_CANCTL1 |= MSCAN_CANCTL1_CANE_MASK; /* Enable CAN mode ************/
MSCAN_CANCTL0 |= MSCAN_CANCTL0_INITRQ_MASK; /* Enable INIT mode ************/
MSCAN_CANCTL1 |= MSCAN_CANCTL1_INITAK_MASK; /* Enable INIT mode ************/
while ((MSCAN_CANCTL1&0x01)!=1); /* wait for initialization mode */
MSCAN_CANCTL0 |= MSCAN_CANCTL0_TIME_MASK; /* time stamping */
MSCAN_CANCTL1 |= MSCAN_CANCTL1_CLKSRC_MASK; /* Enable CLK source ***********/ //not for time stamping(internal clock
MSCAN_CANBTR0 = 0x01; /* prescaler set to 2 **********/
MSCAN_CANBTR1=0x3E; /* SEG SEG1 SEG2 ***************/ //(generates 500 Kbps)
MSCAN_CANCTL0 &= ~MSCAN_CANCTL0_INITRQ_MASK; /* Disable INIT mode ***********/
MSCAN_CANCTL1 &= ~MSCAN_CANCTL1_INITAK_MASK; /* Disable INIT mode ***********/
}