2018-08-14 01:17 PM
Good day to all,
I have STM8Adiscovery and i'm trying to load example from StdPh for the Can Bus but it's not working at all.
Development tool IAR for STM8.
What I have - as i see from the beggining, program try to send data 2 times - and then Can bus start to be un active as i understand that because buffer of mailboxes is full. But in this time i don't any signals on the osciloscope.
For sniff CAN buss i'm using IXXAT USB-to-CAN compact - that tool also don't see any kind of messages. I checked several examples, tryed to configure by my self but still don't have working driver (((((
Could someone check my source codes and give some advices.
Thank you!
void CanDriver_Init( 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_32Bit;
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);
}
---------------------------
INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8)
{
// Receiver Receives Frame
CAN_Receive();
}
----------------------------
void CanDriver_Process( void )
{
CAN_TxStatus_TypeDef status = CAN_TxStatus_Failed;
/* Transmit Parameters */
CAN_Id_TypeDef Tx_IDE = CAN_Id_Standard;
CAN_RTR_TypeDef Tx_RTR = CAN_RTR_Data;
uint8_t Tx_DLC = 0;
uint8_t Tx_Data[8] = {0};
uint32_t Tx_Id = 0;
// Transmit Parameters
Tx_Id = 0x321;
Tx_IDE = CAN_Id_Standard;
Tx_RTR = CAN_RTR_Data;
Tx_DLC = 1;
Tx_Data[0] = 0xAA;
Tx_Data[1] = 0x11;
Tx_Data[2] = 0xBB;
Tx_Data[3] = 0x22;
Tx_Data[4] = 0xCC;
Tx_Data[5] = 0x33;
Tx_Data[6] = 0xDD;
Tx_Data[7] = 0x44;
// Sender send Frame
status = CAN_Transmit(Tx_Id,Tx_IDE,Tx_RTR,Tx_DLC,Tx_Data);
}
For CLK
void CLK_Init(void)
{
CLK_DeInit();
CLK_HSECmd(ENABLE);
/* Configure the Fcpu to DIV1*/
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
/* Output Fcpu on CLK_CCO pin */
CLK_CCOConfig(CLK_OUTPUT_HSE);
/* Configure the system clock to use HSE clock source and to run at 16Mhz */
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
CLK_PeripheralClockConfig( CLK_PERIPHERAL_TIMER1, ENABLE);
CLK_PeripheralClockConfig( CLK_PERIPHERAL_TIMER3, ENABLE);
CLK_PeripheralClockConfig( CLK_PERIPHERAL_CAN, ENABLE);
}
For GPIO
// CAN_TX
GPIO_Init( GPIOG, GPIO_PIN_0, GPIO_MODE_OUT_PP_HIGH_FAST );
// CAN_RX
GPIO_Init( GPIOG, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT );