CAN START Probem
Hi, let me clarify more my situation ... I am coding this from scratch i am using a CAN transciever...My problem is that the CAN_Start function always returns an Error and while debugging i noticed that my code is stuck in the CAN initialisation what i see is that the BIT INAK in the MSR register stayd always 1 when it should switch to 0...probably i have a problem in the config ...This is my config code :
void can_gpio_init(void) {
/*1 Enable Clock Access to GPIOB*/
RCC->AHB1ENR |= GPIODEN;
/*2 Set PD0 and PD1 to alternate function mode*/
GPIOD->MODER &=~(1U<<0);
GPIOD->MODER |=(1U<<1);
GPIOD->MODER &=~(1U<<2);
GPIOD->MODER |=(1U<<3);
GPIOD->PUPDR |=(1U<<0);
GPIOD->PUPDR &=~(1U<<1);
GPIOD->PUPDR |=(1U<<2);
GPIOD->PUPDR &=~(1U<<3);
GPIOD->OTYPER &=~(1U<<0);
GPIOD->OTYPER &=~(1U<<1);
/*3 SET PD0 and PD1 alternate function to CAN1 RX and TX*/
GPIOD->AFR[0] = (CAN_AF<<0);
GPIOD->AFR[0]= (CAN_AF<<4);
/*4 Enable CAN RX0 Interrupt for message reception*/
NVIC_EnableIRQ(CAN1_RX0_IRQn);
}
void can_parms_init(uint8_t mode){
/*1 Enable Clock Access to CAN1*/
RCC->APB1ENR |= RCC_APB1ENR_CAN1EN;
/*2 Enter Initialization mode*/
CAN1->MCR |= CAN_MCR_INRQ;
/*3 Wait until CAN1 is in Initialization mode*/
while ((CAN1->MSR & CAN_MSR_INAK)==0) {}
/*4 Exit Sleep Mode*/
CAN1->MCR &=~ CAN_MCR_SLEEP;
/*5 Wait until CAN1 is OUT of Sleep Mode*/
while ((CAN1->MSR & CAN_MSR_SLAK)) {}
/*5 Configure timing parameters including baudrate by configuring time segment 1 and 2 and prescaler*/
CAN1->BTR = (11<< CAN_BTR_TS1_Pos) | (2 << CAN_BTR_TS2_Pos) | (5 << CAN_BTR_BRP_Pos);
/*6 Select Mode*/
if (mode) {
/*Normal Mode*/
CAN1->BTR &=~(1<<30);
}
else {
//loopBack mode
CAN1->BTR |=(1<<30);
}
}
