this is my program for can transmit .i just want to see through 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 #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 = 5; 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 uint32_t i; uint8_t TransmitMailbox = 0; // sprintf(TxMessage.Data, "Imran\n"); TransmitMailbox = CAN_Transmit(CAN1, &TxMessage); i = 0; while((CAN_TransmitStatus(CAN1, TransmitMailbox) != CANTXOK) && (i != 0xFFFFFF)) // Wait on Transmit { i++; } } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif
Do you have a CAN Transceiver connected? Samplepoint around 50%? I cannot see, that you go buson.
hello i was thinking stm32f4 has built in can transciever kindly guide me how can i work with it do i need to connect externally and do i have to write some code for it.i am new to can so i do not know much about it.
Please check the difference between CAN controller and CAN transceiver. You need both. The CAN controller in included and your source is for it. The CAN transceiver is a "level converter".
Maybe try to do the GPIO_PinAFConfig after your GPIO_Init. I slightly remember a case, where the implementation of GPIO_Init had reset the dedicated AF registers. But I am not sure, if it applies to the stm32f4. Just give it a try, I'd say.
1 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; |
2 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; |
3 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
4 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; |
5 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; |
6 | GPIO_Init(GPIOD, &GPIO_InitStructure); |
7 | |
8 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1); |
9 | GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1); |
And on the CAN TX pin, you should be able to see some flickering, just not what you would expect on the actual CAN bus. Well, at least until your CAN controller goes into Bus Off mode.
Lars F. schrieb: > And on the CAN TX pin, you should be able to see some flickering, just > not what you would expect on the actual CAN bus. > Well, at least until your CAN controller goes into Bus Off mode. Without CAN Tranceiver you see this observation only, if you ensure, that the CAN RX Pin is in rezessive State (High). In other case the CAN controller do not switch in the buson state.
hello! thank you for your responses i connected transciever and i see some wave also on oscilloscope. but the problem is i am seeing this wave on all the pins of transciever and i am also seeing the same wave at the transmit point of db9 module. am i doing something wrong?? the program which i have written is this okay or does it have some kind of mistake??? on my board db9 module is only connected with pin 0 and pin 1 thats why i am using in my code pin 0 and pin 1. and also kindly tell me in this case TX will be CAN_H and RX will be CAN_L??? as i am transmitting the data. i will be waiting for your kind response
CAN RX -> RXD CAN TX -> TXD CAN-H and CAN-L is your CAN bus Please check the datasheet and manual of the transceiver. Typical there are many pictures. ;-) Check, that you have a bus termination (resistor). Without details nobody can say, if 'some wave' is a CAN message. Do you use a CAN analyser? Send a message with it and you can see a correct CAN message wave. Please check the hint of Lars.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.