cancel
Showing results for 
Search instead for 
Did you mean: 

CAN not working on STM32F205 (proto board)

vneff
Associate II
Posted on April 06, 2014 at 17:27

Hi,

It is possible that the hardware has gone bad, but I consider it unlikely.  I swear that this use to work.

The same software works OK on the STM3221G-eval board.

I know there is a signal at the CAN rx input to the processor.

I've gone back to the CAN loopback  demo software that comes with the STM32F2xx_StdPeriph_Lib_V1.1.0 package.

In loopback mode, everything works just fine, both in the polling and interrupt versions.

When set the CAN_mode to Normal, Nothing is received using polling or interrupts.

The baudrate is 500,000 and I have set the prescale divider to 4, with 15 quanta bits.

As in the demo, the filter is set to receive anything, ie. the mask is set to 0 and the ID is set to 0.

I've tried with bus loaded and not with no difference.

I'll try to capture the signal going into the processor on the eval board and the proto board to see if there is any difference when I get back to the office.

Is there anything else I can check to help determine the problem???

I can include the code, but it is very basic at this point.

Thanks for any insight!

Vance

9 REPLIES 9
Posted on April 06, 2014 at 18:06

The baudrate is 500,000 and I have set the prescale divider to 4, with 15 quanta bits.

Can you provide details of you APB/AHB speeds, and the initialization values/structure for the CAN peripheral?

What transceiver are you using, and how is this wired up?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vneff
Associate II
Posted on April 06, 2014 at 23:27

Thanks Clive,

The transceiver is the NXP TJF1 I don't have a schematic. This is in a Janus Terminus T2 device. The PCLK1 is running at 30Mhz and the HCLK is running at 120Mhz. Here is the initialization procedure for CAN1, which is what I am using:

/* CAN register init */
CAN_DeInit(CAN1);
/* CAN cell init */
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 = (loopback)?CAN_Mode_LoopBack:CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
/* CAN Baudrate = 500kbps (CAN clocked at 30 MHz) */
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = 4;
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
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 = 0;
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);

All works fine for when loopback is set, so it does make me think of baudrate issue; but, every thing seem to set properly. Thanks for looking into this! Vance
Posted on April 07, 2014 at 02:00

Give this a try

//******************************************************************************
//
// JANUS TERMINUS2 USART3 / CAN RX Demo 500 Kbps
//
//******************************************************************************
//
// Modified system_stm32f2xx.c
//
// * HSE Frequency(Hz) | 16000000
// * PLL_M | 16
// #define PLL_M 16
//
// HSE_VALUE 16000000
//
//******************************************************************************
#include <
stdio.h
>
#include <
stdlib.h
>
#include <
string.h
>
#include ''stm32f2xx.h''
//******************************************************************************
void CAN_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_ClocksTypeDef RCC_Clocks;
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
RCC_GetClocksFreq(&RCC_Clocks);
RCC_AHB1PeriphClockCmd(
RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE,
ENABLE);
/* CAN */
/* Configure PE.06 (CAN EN) as output */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* GPIO PD.00 (CAN_RX) and PD.01 (CAN_TX) Configuration */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect CAN_RX and CAN_TX */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_CAN1);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_CAN1);
GPIO_SetBits(GPIOE, GPIO_Pin_6); // PE.6 High (CANEN=1) Disabled
/* CANx Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
/* CAN register init */
CAN_DeInit(CAN1);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
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_Mode_LoopBack;
/* quanta 1+6+8 = 15, 15 * 4 = 60, 30000000 / 60 = 500000 */
/* CAN Baudrate = 125kbps (CAN clocked at 30 MHz) Prescale = 4 */
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_8tq;
CAN_InitStructure.CAN_Prescaler = RCC_Clocks.PCLK1_Frequency / (15 * 500000); // quanta by baudrate
CAN_Init(CAN1, &CAN_InitStructure);
/* CAN filter init */
#if 1 // CAN1
CAN_FilterInitStructure.CAN_FilterNumber = 0; // CAN1 [ 0..13]
#else // CAN2
CAN_FilterInitStructure.CAN_FilterNumber = 14; // CAN2 [.27]
#endif
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; // IdMask or IdList
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit; // 16 or 32
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000; // Everything
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; // Rx
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
GPIO_ResetBits(GPIOE, GPIO_Pin_6); // PE.6 Low (CANEN=0) Enabled - Transmit
}
//******************************************************************************
void CAN_RxTest(void)
{
CanRxMsg RxMessage;
volatile uint32_t i = 0;
puts(''CAN_RxTest'');
while(1)
{
memset(&RxMessage, 0, sizeof(RxMessage));
i = 0;
while((CAN_MessagePending(CAN1, CAN_FIFO0) < 
1
) && (i <= 0xFFFFFF)) // Wait on receive
{
i++;
}
if (i >= 0xFFFFFF) { printf(''TIMEOUT %08X %d
'', i, CAN_MessagePending(CAN1, CAN_FIFO0)); continue; }
/* receive */
CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
printf(''PASSED %02X %02X %02X %02X %02X %02X %02X %02
X'',
RxMessage.Data[0],RxMessage.Data[1],RxMessage.Data[2],RxMessage.Data[3],
RxMessage.Data[4],RxMessage.Data[5],RxMessage.Data[6],RxMessage.Data[7]);
} // while
}
//******************************************************************************
void USART3_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
// Initialization of Terminus 2 (T2) RS232 port for debugging
RCC_AHB1PeriphClockCmd(
RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOF,
ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* Enable USART3 Clock */
/* Configure PF3 FORCEON, PF4 FORCEOFF - RS232 */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_SetBits(GPIOF, GPIO_Pin_3 | GPIO_Pin_4); // Both High
/* USART RS232 */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3); /* Connect PB10 to USART3_Tx */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3); /* Connect PB11 to USART3_Rx */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_USART3); /* Connect PD11 to USART3_CTS */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_USART3); /* Connect PD12 to USART3_RTS */
/* Configure USART3 Tx & Rx as alternate function */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 CTS & RTS as alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure); /* Configure USART */
USART_Cmd(USART3, ENABLE); /* Enable the USART */
}
//******************************************************************************
int main(void)
{
USART3_Configuration(); // Setup USART for debugging on T2
puts(''CAN Rx Test'');
CAN_Configuration();
CAN_RxTest();
while(1); /* Infinite loop */
}
//******************************************************************************
// Hosting of stdio functionality through USART3 - Keil
//******************************************************************************
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART3);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
//******************************************************************************
#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

'', file, line) */
while(1); /* Infinite loop */
}
#endif
//******************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vneff
Associate II
Posted on April 07, 2014 at 15:21

Thanks again!

Your sample code worked!

First, it was a mistake to use the CAN/LoopBack example for my back to basics testing.  I should have used the CAN/Networking instead.  The loopback example did not have to initialize the pins.

When I compared your example to my actual code, the only real difference was that I was not initializing the CAN chip enable pin.  That probably explains why the code seemed to work at one time and not later.  Definitely, a bad oversight.

Thank you very much for helping me!

Vance

Posted on April 08, 2014 at 00:35

You're welcome.

http://www.janus-rc.com/TerminusT2.html

0690X00000602sOQAQ.jpg

0690X00000602sJQAQ.jpg

0690X00000602sTQAQ.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 06, 2017 at 15:25

Now, I wonder what the exactly CPU you are using ,My CPU is STM32F205ZET6, but I can not find the CANEN pin ,please help!

Posted on March 06, 2017 at 15:25

Now, I wonder what the exactly CPU you are using ,My CPU is STM32F205ZET6, but I can not find the CANEN pin ,please help!

Posted on March 06, 2017 at 16:39

It is specific to the board, you likely don't have it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 07, 2017 at 01:28

Thanks anyway