cancel
Showing results for 
Search instead for 
Did you mean: 

CAN

romancorba
Associate
Posted on April 19, 2013 at 01:25

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 */

 

&sharpdefine PLL_M      25

 

&sharpdefine PLL_N      336

 

 

/* SYSCLK = PLL_VCO / PLL_P */

 

&sharpdefine PLL_P      2

 

 

/* USB OTG FS, SDIO and RNG Clock =  PLL_VCO / PLLQ */

 

&sharpdefine PLL_Q      7

 

 

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

program:

&sharpdefine CANx                       CAN1

 

&sharpdefine CAN_FILTER_NMR              0

 

&sharpdefine CAN_CLK                    RCC_APB1Periph_CAN1

 

&sharpdefine CAN_RX_PIN                 GPIO_Pin_8

 

&sharpdefine CAN_TX_PIN                 GPIO_Pin_9

 

&sharpdefine CAN_GPIO_PORT              GPIOB

 

&sharpdefine CAN_GPIO_CLK               RCC_AHB1Periph_GPIOB

 

&sharpdefine CAN_AF_PORT                GPIO_AF_CAN1

 

&sharpdefine CAN_RX_SOURCE              GPIO_PinSource0

 

&sharpdefine 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){};

 

}

#can-keil-c-uvision-4
1 REPLY 1
Posted on April 19, 2013 at 01:38

    // alternativni funkce

 

    GPIO_PinAFConfig(GPIOB, GPIO_Pin_9, GPIO_AF_CAN1); // PinSource ! PinSource !

 

    GPIO_PinAFConfig(GPIOB, GPIO_Pin_8, GPIO_AF_CAN1);

 

 

 

  GPIO_Init(GPIOD, &GPIO_InitStructure); //<<< GPIOB

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..