cancel
Showing results for 
Search instead for 
Did you mean: 

STM8AF5288 - CAN issues

Rx7TyreBurna
Associate II

I'm trying to get my STM8AF5288 to read CAN from a TJA1050.

I had it reading perfectly.  1Mbps @ 16Mhz.  Using time_seg1 of 8, tim_seg2 of 7, prescale of 1.  SJW1.

The sending unit is an Arduino attached to an MCP2515 and TJA1050.  Verified with another arduino unit that it can read the sending on the CAN bus.

Now, I decided that after utilizing the internal clock and being able to read CAN, I would switch to an external resonator.  Threw that on, and suddenly couldn't get CAN to work anymore.  I hadn't even selected the external clock to be used.  Still had internal setup in the code.

So, I removed the resonator I installed.  Still can't get CAN.

I have 7x of these PCB, so I thought maybe I messed something up.  Rebuilt another w/ all new components.  Still not seeing CAN.

I am getting stuff populated in the CAN FIFO data.  But, it's always the same thing and appears to be 'junk'.  Where, previously I was seeing the correct standard ID and 8 data bytes following.

For my purpose (automotive, hobby / non-commercial), I ultimately need to read 500Kbps.  Which I am seeing prescale 2, seg 1 @ 13, seg 2 @ 2, sjw of 1.  Using bittiming.can-wiki.info.

The thing I'm trying to figure out, is what would cause the signal to not be suddenly read?  I'm at a complete loss of where to look, where to even begin....  from working, to suddenly not working....

I took the CAN code from the example, and like mention, everything was working fine.  Currently setting HSI clock via 

 

CLK_DeInit();
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);

 

 

Any information is greatly appreciated, thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Alright, it looks like there is something wrong in my PCB design.  Using an external TJA1050, I am able to get CAN to the STM8 again.

View solution in original post

4 REPLIES 4
Rx7TyreBurna
Associate II

Here is the code I'm testing with right now, which previously worked.  Changed transmitter to go back to 1Mbps, so I'm using the sample code that should be reading 1Mbps.

 

/* MAIN.C file
 * 
 * Copyright (c) 2002-2005 STMicroelectronics
 */
#include "main.h"

main()
{
	CLK_DeInit();
	CLK->CKDIVR = 0;
	
	CAN_Config();
	
	while (1)
	{
		CAN_Receive();
	}
}

void CAN_Config(void)
{
  CAN_InitStatus_TypeDef status = CAN_InitStatus_Failed;
  
  /* Filter Parameters */
  CAN_FilterNumber_TypeDef CAN_FilterNumber;
  FunctionalState CAN_FilterActivation;
  CAN_FilterMode_TypeDef CAN_FilterMode;
  CAN_FilterScale_TypeDef CAN_FilterScale;
  uint8_t CAN_FilterID1;
  uint8_t CAN_FilterID2;
  uint8_t CAN_FilterID3;
  uint8_t CAN_FilterID4;
  uint8_t CAN_FilterIDMask1;
  uint8_t CAN_FilterIDMask2;
  uint8_t CAN_FilterIDMask3;
  uint8_t CAN_FilterIDMask4; 
  
  /* Init Parameters*/
  CAN_MasterCtrl_TypeDef CAN_MasterCtrl;
  CAN_Mode_TypeDef CAN_Mode;
  CAN_SynJumpWidth_TypeDef CAN_SynJumpWidth;
  CAN_BitSeg1_TypeDef CAN_BitSeg1;
  CAN_BitSeg2_TypeDef CAN_BitSeg2;
  uint8_t CAN_Prescaler;  
  
  /* CAN register init */
  CAN_DeInit();
    
  /* CAN  init */
  CAN_MasterCtrl=CAN_MasterCtrl_AllDisabled;
  CAN_Mode = CAN_Mode_Normal;
  CAN_SynJumpWidth = CAN_SynJumpWidth_1TimeQuantum;
  CAN_BitSeg1 = CAN_BitSeg1_8TimeQuantum;
  CAN_BitSeg2 = CAN_BitSeg2_7TimeQuantum;
  CAN_Prescaler = 1;
  status = CAN_Init(CAN_MasterCtrl, CAN_Mode, CAN_SynJumpWidth, CAN_BitSeg1, \
                    CAN_BitSeg2, CAN_Prescaler);

  /* CAN filter init */
  CAN_FilterNumber = CAN_FilterNumber_0;
  CAN_FilterActivation = ENABLE;
  CAN_FilterMode = CAN_FilterMode_IdMask;
  CAN_FilterScale = CAN_FilterScale_16Bit;
  CAN_FilterID1=0;  
  CAN_FilterID2=0;
  CAN_FilterID3=0;
  CAN_FilterID4=0;
  CAN_FilterIDMask1=0;
  CAN_FilterIDMask2=0;
  CAN_FilterIDMask3=0;
  CAN_FilterIDMask4=0;  
  CAN_FilterInit(CAN_FilterNumber, CAN_FilterActivation, CAN_FilterMode, 
                 CAN_FilterScale,CAN_FilterID1, CAN_FilterID2, CAN_FilterID3,
                 CAN_FilterID4,CAN_FilterIDMask1, CAN_FilterIDMask2, 
                 CAN_FilterIDMask3, CAN_FilterIDMask4);
        
  /* Enable Fifo message pending interrupt*/
  /* Message reception is done by CAN_RX ISR*/
  CAN_ITConfig(CAN_IT_FMP, ENABLE);
}

Checked clock on CLK_CCO, verified a solid 16Mhz.

Power looks great throughout the board.

Because it was working before, I suspect there is something in the code somewhere.

Keeping on it.  STM8AF series seems like a great package for small auto applications.  Hoping to get this working.

I used a logic analyzer to check the signals going into the TJA1050.  Everything looks good.

I was thinking, I do the CAN_Init(), but never do anything for the interfaces.  Do I need to declare RX as input and TX as output?  Pull high, pull low, push-pull?

 

Alright, it looks like there is something wrong in my PCB design.  Using an external TJA1050, I am able to get CAN to the STM8 again.