AnsweredAssumed Answered

CAN

Question asked by Sleepz on Apr 19, 2013
Latest reply on Apr 19, 2013 by Clive One
Hello, im trying to comunicate with other kits on CAN. After 4 weeks, I still have not found a solution... Can someone help me with CAN please? :-(
I have tranceiver, and need comunicate with standart CAN protocol.
When im debuging this, CAN wake up from sleep, but cant come out from INAK on MSR.
If someone have working project on keil, I will be grateful.


clocks:
/************************* PLL Parameters *************************************/
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
#define PLL_M      25
#define PLL_N      336

/* SYSCLK = PLL_VCO / PLL_P */
#define PLL_P      2

/* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */
#define PLL_Q      7

/******************************************************************************/

program:

#define CANx                       CAN1
#define CAN_FILTER_NMR              0
#define CAN_CLK                    RCC_APB1Periph_CAN1
#define CAN_RX_PIN                 GPIO_Pin_8
#define CAN_TX_PIN                 GPIO_Pin_9
#define CAN_GPIO_PORT              GPIOB
#define CAN_GPIO_CLK               RCC_AHB1Periph_GPIOB
#define CAN_AF_PORT                GPIO_AF_CAN1
#define CAN_RX_SOURCE              GPIO_PinSource0
#define CAN_TX_SOURCE              GPIO_PinSource1

int main(void){
    // inicializace struktur
    GPIO_InitTypeDef GPIO_InitStructure;
    // zapnuti hodin
    RCC_AHB1PeriphClockCmd(CAN_GPIO_CLK, ENABLE);
    
    // alternativni funkce
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_9, GPIO_AF_CAN1);
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_8, GPIO_AF_CAN1);
    // inicializace GPIO
    GPIO_DeInit(GPIOB);
  /* Configure PD0 in R */
  GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Configure PD1 out T */
  GPIO_InitStructure.GPIO_Pin = CAN_TX_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
    
    
    // Hodiny CAN
    RCC->APB1ENR |= RCC_APB1Periph_CAN1;
    // RESET CAN
    RCC->APB1RSTR |= RCC_APB1Periph_CAN1;
    RCC->APB1RSTR &= ~RCC_APB1Periph_CAN1;
    // probuzeni CAN ze sleepu
    CAN1->MCR &= (~(uint32_t)CAN_MCR_SLEEP);
    // request inicializace
    CAN1->MCR |= CAN_MCR_INRQ ;
    // nastavení casovani
//   CAN1->BTR = (uint32_t)((uint32_t)((uint8_t)0x00) << 30) | \
//                 ((uint32_t)((uint8_t)0x00) << 24) | \
//                 ((uint32_t)((uint8_t)0x0D) << 16) | \
//                 ((uint32_t)((uint8_t)0x05) << 20) | \
//                ((uint32_t)16 - 1);
    // request deinicializace
    CANx->MCR &= ~(uint32_t)CAN_MCR_INRQ;            
    while(1){};
}

Outcomes