-2

This is my program for CAN transmit. I just want to see through the oscilloscope wether something is being sent or not. I am using stm32f407 and attolic true studio for it, but i am unable to see any signal on my tx pin. Kindly tell me where is my mistake. Do i need to connect the transciever externally and also how can i access CAN_H and CAN_L pins.

#include "stm32f4xx.h"
int main(void)
{
  GPIO_InitTypeDef      GPIO_InitStructure;

  RCC_ClocksTypeDef     RCC_Clocks;
CAN_InitTypeDef       CAN_InitStructure;
 CAN_FilterInitTypeDef CAN_FilterInitStructure;
  CanTxMsg TxMessage;
 RCC_GetClocksFreq(&RCC_Clocks);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);`
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);
 GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
CAN_InitStructure.CAN_TTCM = DISABLE;
 CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = DISABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
 CAN_InitStructure.CAN_TXFP = DISABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
 CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
 CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq;
CAN_InitStructure.CAN_Prescaler = 4;
  CAN_Init(CAN1, &CAN_InitStructure);
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);
  // transmit */
TxMessage.StdId= 0x123;
TxMessage.ExtId= 0x00;
TxMessage.RTR= CAN_RTR_DATA;
TxMessage.IDE= CAN_ID_STD;
TxMessage.DLC= 4;
TxMessage.Data[0]= 0x02;
TxMessage.Data[1]= 0x11;
TxMessage.Data[2]=0x11;
TxMessage.Data[3]=0x11;

while(1)
{

volatile uint_t i;

unit8_t TransmitMailbox= 0;
//sprintf(TxMessage.Data, "Imran\n");


TransmitMailbox= CAN_Transmit(CAN1,&TxMessage);

i=0;
while((CAN_TransmitStatus(CAN1,TransmitMailbox) !=CANTXOK)&& (i !=0xFFFFFF))
{
i++;
} 
}
 }
Mike
  • 4,041
  • 6
  • 20
  • 37
imran
  • 11
  • 2

1 Answers1

1

Try to turn on the Automatic Wake Up by changing to the following line:

CAN_InitStructure.CAN_AWUM = ENABLE;        

The stm32f407 has only the CAN Controller without the internal transciever, so you need to connect it externaly. Also you have to connect another device into your CAN Bus to see something (remember about the terminators).

Please explain what do you mean by saying that:

how can i access CAN_H and CAN_L pins  

PS. You should not put each functionality into one routine because it is unreadable.

pelkaid
  • 41
  • 4
  • i mean in this case my TX pin will be CAN_H and RX will CAN_L. Cant i see anything only using oscilloscope i mean if i do not connect another device i should see some wave on oscilloscope. and kindly explain this "PS. You should not put each functionality into one routine because it is unreadable." – imran Aug 17 '18 at 10:53