AnsweredAssumed Answered

CAN TX Problem

Question asked by yao.randy.001 on Oct 1, 2014
Latest reply on Oct 1, 2014 by Clive One
Hi ST Forum,

Debugging a CAN TX message and can't really do it :(. I connected scope to PB13 and just see a high (3V) signal on the TX line. Anything wrong with my code below?

I'm wondering if it's my CAN_mode. Can anyone tell me what's the difference between normal mode, silent mode and loopback mode?

Thanks,

#include <stm32f4xx_can.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_rcc.h>
#include <semihosting.h>

GPIO_InitTypeDef GPIO_InitStructure;
CAN_InitTypeDef CAN_InitStructure;
CanTxMsg Message1;
CanTxMsg Message2;

void CANInit(void);
void Message(void);

int main(void)
{
     CANInit();
     Message();

    while(1)
    {
         CAN_Transmit(CAN2,&Message1);
    }
}

void CANInit(void){
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2,ENABLE);

     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOB,&GPIO_InitStructure);

     GPIO_PinAFConfig(GPIOB,GPIO_PinSource12,GPIO_AF_CAN2); //CAN_RX = PB12
     GPIO_PinAFConfig(GPIOB,GPIO_PinSource13,GPIO_AF_CAN2); //CAN_TX = PB13

     /* CAN2 reset */
     /* CAN2 configuration */
     CAN_DeInit(CAN2); //De-initialize CAN 2 to start over
     CAN_InitStructure.CAN_TTCM = DISABLE; // time-triggered communication mode = DISABLED
     CAN_InitStructure.CAN_ABOM = DISABLE; // automatic bus-off management mode = DISABLED
     CAN_InitStructure.CAN_AWUM = DISABLE; // automatic wake-up mode = DISABLED
     CAN_InitStructure.CAN_NART = DISABLE; // non-automatic retransmission mode = DISABLED
     CAN_InitStructure.CAN_RFLM = DISABLE; // receive FIFO locked mode = DISABLED
     CAN_InitStructure.CAN_TXFP = DISABLE; // transmit FIFO priority = DISABLED
     CAN_InitStructure.CAN_Mode = CAN_Mode_Silent; // normal CAN mode
     CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; // synchronization jump width = 1
     CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq; //14
     CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq; //6
     CAN_InitStructure.CAN_Prescaler = 2; // baudrate 125kbps
     //CAN_InitStructure.CAN_Prescaler = 4; // baudrate 500 kbps
     CAN_Init(CAN2, &CAN_InitStructure);
}

void Message(void){
     Message1.RTR = CAN_RTR_Data; //transmit data (master to slave) remote frame is a destination node requesting data
     Message1.IDE = CAN_Id_Standard; //Standard identifier length
     Message1.StdId = 0x7FF; //Identifier and priority
     Message1.DLC = 1; //8 bit data
     Message1.Data[0] = (uint8_t)0xAA; //actual message
}

Outcomes