Svetelektro.com

Svetelektro.com

Meno:
Heslo:
SVETELEKTRO • STM32F103C8T6 - probl├ęm se sb─Ťrnic├ş CAN

STM32F103C8T6 - probl├ęm se sb─Ťrnic├ş CAN

C,C++,C#

Moderátori: psichac, Moderátori

STM32F103C8T6 - probl├ęm se sb─Ťrnic├ş CAN

Odosla┼ąod StavJi » 23 Jan 2017, 19:36

Zdrav├şm,

pros├şm V├ís nev┼íiml by si n─Ťkdo n─Ťjak├ę chyby? Oba konce sb─Ťrnice jsou zakon─Źeny rezistory 120R a propojeny cca 0,5m kroucen├ęho kabliku. Pro lad─Ťn├ş pou┼ż├şv├ím toto https://imfsoft.com/kategorie-can-bus/u ... high-speed s t├şm, ┼że v obslu┼żn├ęm SW se na─Ź├ştaj├ş pouze chyby, ale ┼ż├ídn├í data nedoraz├ş.

K├│d: Vybra┼ą v┼íetko
void CAN_Configuration()
{
   CAN_InitTypeDef         CAN_InitStructure;
   CAN_FilterInitTypeDef   CAN_FilterInitStructure;
   NVIC_InitTypeDef      NVIC_InitStructure;
   GPIO_InitTypeDef      GPIO_InitStructure;

   // Povoleni hodin GPIO
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

   // Povoleni hodin CAN
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

    CAN_DeInit(CAN1);
    CAN_StructInit(&CAN_InitStructure);

    // Nastaveni CAN ramce
    CAN_InitStructure.CAN_TTCM = DISABLE;
    CAN_InitStructure.CAN_ABOM = DISABLE;
    CAN_InitStructure.CAN_AWUM = DISABLE;
    CAN_InitStructure.CAN_NART = DISABLE;//ENABLE;//
    CAN_InitStructure.CAN_RFLM = DISABLE;
    CAN_InitStructure.CAN_TXFP = DISABLE;//ENABLE;//
    CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;

    // 500 kbps
    CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
    CAN_InitStructure.CAN_BS1 = CAN_BS1_12tq;
    CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;

    //CAN_InitStructure.CAN_Prescaler=1;        // 2000 kbit/s
    //CAN_InitStructure.CAN_Prescaler=2;        // 1000 kbit/s
    //CAN_InitStructure.CAN_Prescaler=4;        //  500 kbit/s
    //CAN_InitStructure.CAN_Prescaler=5;        //  400 kbit/s
    //CAN_InitStructure.CAN_Prescaler=8;        //  250 kbit/s
    //CAN_InitStructure.CAN_Prescaler=10;       //  200 kbit/s
    //CAN_InitStructure.CAN_Prescaler=16;       //  125 kbit/s
    //CAN_InitStructure.CAN_Prescaler=20;         //  100 kbit/s
    //CAN_InitStructure.CAN_Prescaler=40;       //   50 kbit/s
    //CAN_InitStructure.CAN_Prescaler=80;       //   40 kbit/s
    CAN_InitStructure.CAN_Prescaler=200;      //   10 kbit/s

    CAN_Init(CAN1, &CAN_InitStructure);

    // Nastaveni filtru zprav CAN
    CAN_FilterInitStructure.CAN_FilterNumber = 0;
    CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
    CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
    CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
    CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
    CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
    CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
    CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;
    CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
    CAN_FilterInit(&CAN_FilterInitStructure);

    CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);

    /* 2 bit for pre-emption priority, 2 bits for subpriority */
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
    NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

  // Configure CAN pin: RX
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // Configure CAN pin: TX
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

   //GPIO_PinRemapConfig(GPIO_Remap2_CAN1 , ENABLE);

   // prenos
   CanTxMsg TxMessage;

   TxMessage.StdId = 0x321;
   TxMessage.RTR = CAN_RTR_DATA;
   TxMessage.IDE = CAN_ID_STD;
   TxMessage.ExtId = 0x01;
   TxMessage.DLC = 8;
}


K├│d: Vybra┼ą v┼íetko
void CAN_send()
{
   CanTxMsg TxMessage;

   /*TxMessage.StdId = 0x00;
   TxMessage.RTR = CAN_RTR_DATA;
   TxMessage.IDE = CAN_ID_STD;
   TxMessage.ExtId = 0x00;*/

   TxMessage.Data[0] = 0x04;
   TxMessage.Data[1] = 0x01;
   TxMessage.Data[2] = 0x00;
   TxMessage.Data[3] = 0x00;
   TxMessage.Data[4] = 0x00;
   TxMessage.Data[5] = 0x00;
   TxMessage.Data[6] = 0x00;
   TxMessage.Data[7] = 0x00;
   //TxMessage.DLC = 8;

   CAN_Transmit(CAN1, &TxMessage);
}
Pr├şlohy
CAN.png
Zapojen├ş na DPS
StavJi
Okoloid├║ci
Okoloid├║ci
Pr├şspevky: 35
Zalo┼żen├Ż: 22.01.2014
Bydlisko: Olomouc
Karma: 0

Nasp├Ą┼ą na C,C++,C#

Kto je pr├ştomn├Ż

U┼ż├şvatelia prezeraj├║ci si toto f├│rum: ┼Żiadny registrovan├Ż pou┼ż├şvate─ż a 2 host├ş.

Forums ©
Autor str├ínky je Ondrej Z├ívodsk├Ż(zawin), o graficky design sa star├í ─Żubo┼í Fabo(BUFU).

TOPlist

Powered by Copyright © UNITED-NUKE CMS. All Rights Reserved.
─îas potrebn├Ż k spracovaniu str├ínky 0.07 sek├║nd