Forum: Mikrocontroller und Digitale Elektronik stm32f4 discovery can transmit problem


Announcement: there is an English version of this forum on EmbDev.net. Posts you create there will be displayed on Mikrocontroller.net and EmbDev.net.
von Muhammad I. (Firma: uni rostock) (imran93)


Bewertung
0 lesenswert
nicht lesenswert
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

von Steffen R. (steffen_rose)


Bewertung
0 lesenswert
nicht lesenswert
Do you have a CAN Transceiver connected?

Samplepoint around 50%?

I cannot see, that you go buson.

von Muhammad I. (Firma: uni rostock) (imran93)


Bewertung
0 lesenswert
nicht lesenswert
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.

von Steffen R. (steffen_rose)


Bewertung
0 lesenswert
nicht lesenswert
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".

von Lars F. (flemmy)


Bewertung
0 lesenswert
nicht lesenswert
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.

von Steffen R. (steffen_rose)


Bewertung
0 lesenswert
nicht lesenswert
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.

von Muhammad I. (Firma: uni rostock) (imran93)


Bewertung
0 lesenswert
nicht lesenswert
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

von Steffen R. (steffen_rose)


Bewertung
0 lesenswert
nicht lesenswert
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.

Antwort schreiben

Die Angabe einer E-Mail-Adresse ist freiwillig. Wenn Sie automatisch per E-Mail über Antworten auf Ihren Beitrag informiert werden möchten, melden Sie sich bitte an.

Wichtige Regeln - erst lesen, dann posten!

  • Groß- und Kleinschreibung verwenden
  • Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang

Formatierung (mehr Informationen...)

  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] - Link zu Artikel
  • Verweis auf anderen Beitrag einfügen: Rechtsklick auf Beitragstitel,
    "Adresse kopieren", und in den Text einfügen




Bild automatisch verkleinern, falls nötig
Bitte das JPG-Format nur für Fotos und Scans verwenden!
Zeichnungen und Screenshots im PNG- oder
GIF-Format hochladen. Siehe Bildformate.
Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt.
Bitte hier nur auf die ursprüngliche Frage antworten,
für neue Fragen einen neuen Beitrag erstellen.

Mit dem Abschicken bestätigst du, die Nutzungsbedingungen anzuerkennen.