cancel
Showing results for 
Search instead for 
Did you mean: 

No CAN Transmit on STM32F7 DISCO

Rob Ashworth_2
Associate II
Posted on January 11, 2017 at 15:47

I am having some issues with CAN on my STM32F746 Disco board.

When I send the data as below, I get an error back...

CAN_IT_Status

=

HAL_CAN_Transmit_IT

(

&

CanHandle

)

;

dum1

=

CanHandle

.

State

;

CANErrorCode

=

CanHandle

.

ErrorCode

;

so....

CAN_IT_STATUS=1, dum1=0x04, CANErrorCode=0.

on Probing through the HAL library, I can only assume that the CAN Mailboxes are not being cleared i.e. they are always full.

Does this sound like a hardware configuration thing as in the Message is never sent for some reason, or is there a bug in the library plenty of issues I can seen on this forum about CAN TX/TX Library problems.

If I probe the bus, with a scope there is absolutely nothing!

For info I am using the latest HAL libraries V1.5.

Here is my bus configuration:

void

HAL_CAN_MspInit

(

CAN_HandleTypeDef

*

hcan

)

{

GPIO_InitTypeDef

GPIO_InitStruct

;

/*##-1- Enable peripherals and GPIO Clocks #################################*/

/* Enable GPIO clock ****************************************/

CANx_GPIO_CLK_ENABLE

()

;

/* CAN1 Periph clock enable */

//CANx_CLK_ENABLE();

/*##-2- Configure peripheral GPIO ##########################################*/

/* CAN1 TX GPIO pin configuration */

GPIO_InitStruct

.

Pin

=

CANx_TX_PIN

;

GPIO_InitStruct

.

Mode

=

GPIO_MODE_AF_PP

;

GPIO_InitStruct

.

Speed

=

GPIO_SPEED_HIGH

;

GPIO_InitStruct

.

Pull

=

GPIO_NOPULL

;

GPIO_InitStruct

.

Alternate

=

CANx_TX_AF

;

HAL_GPIO_Init

(

CANx_TX_GPIO_PORT

,

&

GPIO_InitStruct

)

;

/* CAN1 RX GPIO pin configuration */

GPIO_InitStruct

.

Pin

=

CANx_RX_PIN

;

GPIO_InitStruct

.

Mode

=

GPIO_MODE_AF_PP

;

GPIO_InitStruct

.

Speed

=

GPIO_SPEED_HIGH

;

GPIO_InitStruct

.

Pull

=

GPIO_NOPULL

;

GPIO_InitStruct

.

Alternate

=

CANx_RX_AF

;

HAL_GPIO_Init

(

CANx_RX_GPIO_PORT

,

&

GPIO_InitStruct

)

;

}

And CAN Config:

void

CAN_Config

(

void

)

{

char

MyString

[

20

]

;

CAN_FilterConfTypeDef

sFilterConfig

;

HAL_CAN_DeInit

(

&

CanHandle

)

;

//De-Init first

//HAL_CAN_DeInit(&CanHandle);

/* CAN1 Periph clock enable */

CANx_CLK_ENABLE

()

;

/*##-1- Configure the CAN peripheral #######################################*/

CanHandle

.

Instance

=

CANx

;

 

CanHandle

.

pTxMsg

=

&

TxMessage

;

CanHandle

.

pRxMsg

=

&

RxMessage

;

//Calculation is CANCLK/(BRP*(BS1+BS2+1)) = 50/5*(7+2+1) = 1

CanHandle

.

Init

.

TTCM

=

DISABLE

;

CanHandle

.

Init

.

ABOM

=

ENABLE

;

CanHandle

.

Init

.

AWUM

=

DISABLE

;

CanHandle

.

Init

.

NART

=

DISABLE

;

CanHandle

.

Init

.

RFLM

=

DISABLE

;

CanHandle

.

Init

.

TXFP

=

DISABLE

;

CanHandle

.

Init

.

Mode

=

CAN_MODE_NORMAL

;

CanHandle

.

Init

.

SJW

=

CAN_SJW_1TQ

;

//1MBit

CanHandle

.

Init

.

BS1

=

CAN_BS1_7TQ

;

//Aim for between 70% & 85% Bit sampling point

CanHandle

.

Init

.

BS2

=

CAN_BS2_2TQ

;

//

CanHandle

.

Init

.

Prescaler

=

5

;

//2;//?

CanHandle

.

pTxMsg

->

StdId

=

0x321

;

CanHandle

.

pTxMsg

->

ExtId

=

0x1111

;

CanHandle

.

pTxMsg

->

RTR

=

CAN_RTR_DATA

;

CanHandle

.

pTxMsg

->

IDE

=

CAN_ID_STD

;

CanHandle

.

pTxMsg

->

DLC

=

8

;

CanHandle

.

pTxMsg

->

Data

[

0

]

=

0x00

;

CanHandle

.

pTxMsg

->

Data

[

1

]

=

0x01

;

 

if

(

HAL_CAN_Init

(

&

CanHandle

)

!=

HAL_OK

)

{

/* Initialization Error */

Error_Handler

()

;

}

/*##-2- Configure the CAN Filter ###########################################*/

sFilterConfig

.

FilterNumber

=

0

;

sFilterConfig

.

FilterMode

=

CAN_FILTERMODE_IDMASK

;

sFilterConfig

.

FilterScale

=

CAN_FILTERSCALE_32BIT

;

sFilterConfig

.

FilterIdHigh

=

0x0000

;

sFilterConfig

.

FilterIdLow

=

0x0000

;

sFilterConfig

.

FilterMaskIdHigh

=

0x0000

;

sFilterConfig

.

FilterMaskIdLow

=

0x0000

;

sFilterConfig

.

FilterFIFOAssignment

=

0

;

sFilterConfig

.

FilterActivation

=

ENABLE

;

sFilterConfig

.

BankNumber

=

14

;

if

(

HAL_CAN_ConfigFilter

(

&

CanHandle

,

&

sFilterConfig

)

!=

HAL_OK

)

{

/* Filter configuration Error */

Error_Handler

()

;

}

}

1 REPLY 1
Rob Ashworth_2
Associate II
Posted on January 12, 2017 at 10:57

Stand down, I have got my PB8/PB9 pins the wrong way around on the schematic!