cancel
Showing results for 
Search instead for 
Did you mean: 

FDCAN send a data en hexa

sana1
Associate III

 Hello, I'm new to working with STM32 microcontrollers and coding in C. I'm trying to send data in hexadecimal format using the FDCAN bus. However, when I check my code during debugging, I notice that the transmitted data looks different from what I expected. The same thing seems to happen with the received data. Can you offer any advice or help on how to fix this?

sana1_0-1712850593104.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Andrew Neil
Evangelist III

@sana1 wrote:

 Hello, I'm new to working with STM32 microcontrollers and coding in C.


Do you have any experience with any other microcontroller(s) and/or any other language(s) ?

 


@sana1 wrote:

  I'm trying to send data in hexadecimal format


Data is just sent as bytes.

The content of those bytes can be viewed as binary, or octal, or hex, or decimal, or whatever - but that doesn't make any difference to the content of the bytes.

0x0F (hex) is the same value as 15 (decimal) and 017 (octal) and 00001111 (binary).

You can choose what format the debugger uses for display by right-clicking, then choosing 'Number Format', then the format you require:

AndrewNeil_0-1712851499671.png

 

EDIT

All of these are entirely equivalent:

 

// Hex
TxData40[]={ 0x00,       0x00,       0x0F,       0xA0,       0x00,       0x00,       0x00,       0x50       };

// Decimal
TxData40[]={ 0,          0,          15,         160,        0,          0,          0,          80         };

// Octal
TxData40[]={ 0,          0,          017,        0240,       0,          0,          0,          0120       };

// Binary
TxData40[]={ 0b00000000, 0b00000000, 0b00001111 0b10100000, 0b00000000, 0b00000000, 0b00000000, 0b01010000 };

 

They would all result in identical data being sent on the bus

Note that C treats any number beginning with a leading zero digit (not followed by 'x' or 'b') as octal.

 

View solution in original post

3 REPLIES 3
Andrew Neil
Evangelist III

@sana1 wrote:

 Hello, I'm new to working with STM32 microcontrollers and coding in C.


Do you have any experience with any other microcontroller(s) and/or any other language(s) ?

 


@sana1 wrote:

  I'm trying to send data in hexadecimal format


Data is just sent as bytes.

The content of those bytes can be viewed as binary, or octal, or hex, or decimal, or whatever - but that doesn't make any difference to the content of the bytes.

0x0F (hex) is the same value as 15 (decimal) and 017 (octal) and 00001111 (binary).

You can choose what format the debugger uses for display by right-clicking, then choosing 'Number Format', then the format you require:

AndrewNeil_0-1712851499671.png

 

EDIT

All of these are entirely equivalent:

 

// Hex
TxData40[]={ 0x00,       0x00,       0x0F,       0xA0,       0x00,       0x00,       0x00,       0x50       };

// Decimal
TxData40[]={ 0,          0,          15,         160,        0,          0,          0,          80         };

// Octal
TxData40[]={ 0,          0,          017,        0240,       0,          0,          0,          0120       };

// Binary
TxData40[]={ 0b00000000, 0b00000000, 0b00001111 0b10100000, 0b00000000, 0b00000000, 0b00000000, 0b01010000 };

 

They would all result in identical data being sent on the bus

Note that C treats any number beginning with a leading zero digit (not followed by 'x' or 'b') as octal.

 

 

thank u a lot  it work .

The 'Variables' tab only shows local variable - you don't have any local variables at that point, so the tab is empty.