/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / CAN on stm32

Username:     
Password:     
             

Forum

# 1   2010-04-14 08:30:44 CAN on stm32

payatz
New member
From: Poland
Registered: 2010-03-10
Posts: 5

CAN on stm32

Hi! I've got a problem with configuring CAN on STM32. I've managed to write a program based on ST examples to send data by loopback mode. The only problem is, there is no signal going out from the chip. Do I have to define somehow the pinouts for CAN other than just:

  /* Configure CAN pin: RX*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure CAN pin: TX*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

I want to send data on pins no. 96 and 95 (PB9 & PB8). They can be programmed to serve as CAN TX/RX. In the examples, there was only a program written for pins PA12 and PA11. I've got USB port attached to those pins, and a CAN transciver attached to pins 95 and 96.


EDIT: And another thing. I've managed to connect the usb/can pins so that I use different pinouts than I intended to. Now the voltage outputs are correct (2,5V). The problem is, I based on an example by ST for can, and it is kind of strange. The example allows to read data by loopback function using polling and interrupts. I've used the part with interrupts. After startup and basic configurations (clk, interrupts etc.) I wanted to transmit TxMessage - address and so on. The problem is, when the program runs the function responsible for this, the whole board goes to the infinite loop thanks to

u8 i=0;

    while((ret==0xFF)&&(i<0XFFF))
       i++;

     if (i==0xFFF)
         ret=0;


Is it a mistake made by ST or is it a delay loop? This 'while(...)' loop makes the chip ignore interrupts from USART and CAN RX, bu only when using Normal mode of CAN. When I use LoopBack mode, everything works fine, maybe except the lack of any transsmition on CAN_H, CAN_L pinouts of my board. In the loop back mode, there still should be some transsmition from the chip, but the voltages sugest the recessive mode on the CAN interface. Any thoughts?

Last edited by payatz (2010-04-14 13:43:20)

Offline

 

# 2   2010-04-15 07:04:14 CAN on stm32

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: CAN on stm32

I am not an expert with CAN (Yves could have a better answer next week), but a few things that could help :
1. Difficult issue: on the Primer2, CAN and FSMC share the same pins. When the FSMC clock is active, all other alternate functions cannot be used on the STM32F103. The only solution consists in stopping the FSMC clock when using the CAN.
2. Just surprised by  "GPIO_Mode_IPU". Why not using a "AF" mode ?

Offline

 

# 3   2010-04-15 18:36:11 CAN on stm32

Matthias
Member
From: Germany
Registered: 2010-01-30
Posts: 20

Re: CAN on stm32

Hast du eine Gegenstelle an canbus.
Can alleine geht nicht. es müssen immer mindesten 2 Teilnehmer am Canbus sein.
Was für eine Hardware benutzt du?

Do you have a peer to canbus.
Can not go alone. it must always be at least 2 participants Canbus.
What hardware do you use?


http://www.stm32circle.com/projects/project.php?id=113


Wer Rechtschreibfehler findet, darf sie behalten
english by translate.google.com
Whoever finds typos may keep them

Offline

 

# 4   2010-04-16 06:06:41 CAN on stm32

payatz
New member
From: Poland
Registered: 2010-03-10
Posts: 5

Re: CAN on stm32

I use stm32f103b, custom board made by my company. I try to communicate with a vision570 PLC made by unitronics.

"Just surprised by  "GPIO_Mode_IPU". Why not using a "AF" mode ?"

I've tried to use different modes, nothing works, the IPU mode is by default used in the st example.

I know there should be 2 devices at least connected by I'm suprised there is no output in the loopback mode... The other problem is, there is nobody in my company who has ever used CAN and who is able to properlly configure the plc to act as a receiver. Today is my last day of internship so I won't be able to check anything after the weekend. In my oppinion there is something wrong with the board.

Thanks for answers wink

Offline

 

# 5   2010-04-16 14:58:43 CAN on stm32

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: CAN on stm32

Sorry, my answer was not relevant. GPIO_Mode_IPU is ok, and my remark about FSMC concerns only the Primer2.

Offline

 

# 6   2011-09-15 13:13:12 CAN on stm32

nicolasmorardo
New member
Registered: 2011-09-15
Posts: 1

Re: CAN on stm32

Hi, late answer but always useful smile
To use CAN on PB8 & PB9, you probably have to remap alternate functions (cf Reference Manual)
Something like : GPIO_PinRemapConfig(GPIO_RemapX_CAN, ENABLE); (cf AFIO->MAPR)

Offline

 

# 7   2011-09-20 06:51:01 CAN on stm32

jonymac001
New member
Registered: 2011-09-20
Posts: 5

Re: CAN on stm32

The STM32 CAN example program shows how to configure and use the CAN peripheral of STMicroelectronics STM32F103xx microcontroller.

The CAN controller is initialized for 500 kbit/s. A converted analog value is send in the first byte of a CAN message. Received and transmitted byte values are displayed on LCD.

The configuration of the clocks is done using the Configuration Wizard in file STM32_Init.c.

Two µVision targets are available:

    * Simulator where the program runs in the software simulator. A debug script (CAN_Simulate.ini) is used to simulate the analog input and the LCD.

Offline

 

Board footer