Hello,
I am trying to setup my CAN2 module for the STM32F105RC but unable to transmit or recieve data with the CAN analsyer. I have setup the CAN1 module the same way and it works. Is there something missing in my configuration or is there are conlfict between periperals?
CAN 2 Setup
/* Enable clock for CAN2 */ RCC->APB1ENR |= (1 << 26); /* Enable clock for GPIOB and AFIO */ RCC->APB2ENR |= (1 << 3) | (1 << 0); /*Set CAN remap to use PB5 and PB6*/ AFIO->MAPR &= 0xFFBFFFFF; AFIO->MAPR |= 0x00400000; /*Setup rx and tx pin for can*/ GPIOB->CRL &= 0xF00FFFFF; GPIOB->CRL |= 0x0B800000; NVIC_EnableIRQ(CAN2_RX0_IRQn); CAN2->MCR = ((1 << 4) | (1 << 0)); // init mode, disable auto. retransmission // Note: only FIFO 0, transmit mailbox 0 used CAN2->IER = ((1 << 1) | (1 << 0)); // FIFO 0 msg pending, Transmit mbx empty /*Initialise ring buffer*/ Can2Buffer.RingBufRxCtr = 0; Can2Buffer.RingBufRxInPtr = &Can2Buffer.RingBufRx[0]; Can2Buffer.RingBufRxOutPtr = &Can2Buffer.RingBufRx[0]; /* set BTR register so that sample point is at about 72% bit time from bit start */ /* TSEG1 = 12, TSEG2 = 5, SJW = 4 => 1 CAN bit = 18 TQ, sample at 72% */ CAN2->BTR &= ~((( 0x03) << 24) | (( 0x07) << 20) | (( 0x0F) << 16) | ( 0x3FF)); CAN2->BTR |= ((((3-1) & 0x03) << 24) | (((4-1) & 0x07) << 20) | (((11-1) & 0x0F) << 16) | ((brp-1) & 0x3FF));
CAN 2 interrupt
void CAN2_RX0_IRQHandler (void) { if (CAN2->RF0R & 3) { /* message pending ? */ /*Check if buffer is full*/ if (Can2Buffer.RingBufRxCtr < 20) { Can2Buffer.RingBufRxCtr++; /* No, increment character count */ CAN_rdMsg (Can2Buffer.RingBufRxInPtr++, 1); if (Can2Buffer.RingBufRxInPtr == &Can2Buffer.RingBufRx[20]) { /* Wrap IN pointer */ Can2Buffer.RingBufRxInPtr = &Can2Buffer.RingBufRx[0]; } } else { CAN2->RF0R |= (1 << 5); /* Release FIFO 0 output mailbox */ } } }