There is no questions of my hardware,i have tested it with standard CAN transmit program. But on the chibios system,i cant detect any signal on the TX pin of the hardware.I think the CAN configurations of my program are correct, so, what is the reason caused the CAN transmit failure? Can you give me some advice or give me the correct CAN transmmit program of the chibios system?
Here is the code i am now running, showing the CAN config:
Code: Select all
/* PA11 - Normal input (CAN RX).
* PA12 - Normal input (CAN TX).
*/
#define VAL_GPIOACRL 0xA8882AAA /* PA7...PA0 */
#define VAL_GPIOACRH 0x888B8AAA /* PA15...PA8 */
#define VAL_GPIOAODR 0xFFFFFFFF
static const CANConfig cancfg = {
CAN_MCR_TXFP,
CAN_BTR_SJW(0)|CAN_BTR_TS2(4)|
CAN_BTR_TS1(5)|CAN_BTR_BRP(5)
};
/**
* CAN thread.
*/
static WORKING_AREA(waCANThread,4096);
static msg_t CANThread(void *arg)
{
(void)arg;
// EventListener el;
CANRxFrame rxmsg;
BaseChannel *seri=(BaseChannel *)&SD1;
static uint8_t smsg[20]={1},*rmsg;
unsigned char txr[8]={0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
while(1)
{
// chMtxLock(&can_mtx);
msg_t result = canReceive(&CAND1, CAN_ANY_MAILBOX, &rxmsg, TIME_IMMEDIATE);
// chMtxUnlock();
if(result==RDY_OK)
{
if(rxmsg.EID==0x1fffffff)
{
palTogglePad(GPIOB,9);
}
}
palTogglePad(GPIOB, GPIOB_LED_A);
CANTransmit(0x1fffffff,txr,8);
chSysLock();
/* The following function must be called from within a system lock zone. */
size_t bytesAvailable = chnBytesAvailable(seri);
chSysUnlock();
if(bytesAvailable)
{
chnRead(seri, rmsg, bytesAvailable);
palTogglePad(GPIOB,9);
}
smsg[0]=0x11;
chnWrite(seri, smsg, 1);
chThdSleepMilliseconds(1000);
}
return 0;
}
void CANInit(void)
{
palSetPad(GPIOB,9);
canObjectInit(&CAND1);//can be delete,it is implicitly invoked by halInit(),
// chMtxLock(&can_mtx); //
canStart(&CAND1,&cancfg); //
chThdSleepMilliseconds(1000); /* delay: time ms */
// chMtxUnlock(); //
sdStart(&SD1, NULL);
chThdCreateStatic(waCANThread,sizeof(waCANThread),HIGHPRIO,
CANThread,NULL); //
}
void CANTransmit(uint32_t id,uint8_t *data,uint8_t len)
{
// chMtxLock(&can_mtx);
static CANTxFrame txmsg[10];
static int txmsg_ind=0;
txmsg[txmsg_ind].IDE=CAN_IDE_EXT;
txmsg[txmsg_ind].EID=id;
txmsg[txmsg_ind].RTR=CAN_RTR_DATA;
txmsg[txmsg_ind].DLC=len;
memcpy(txmsg[txmsg_ind].data8,data,len);
canTransmit(&CAND1,1,&txmsg[txmsg_ind],MS2ST(50));
txmsg_ind++;
if(txmsg_ind<=10){
txmsg_ind=0;
}
}