cancel
Showing results for 
Search instead for 
Did you mean: 

Send 16 bit number with SPI and HAL library

mvugs9
Associate II
Posted on October 12, 2015 at 16:33

Hello

I'm trying to send a 16 bit number with the SPI peripheral on a STM32F030 with the new HAL libary. Sending an 8 bit value is very easy but with a 16 bit number I receive errors or the hardware is crashing with a hardfault error.

void
Rfm69_Write_Reg(uint8_t address, uint8_t value) 
{
reg[0] = value;
reg[1] = address | 0x80;
HAL_SPI_Transmit(&hspi1, (uint8_t *)reg, 1, 1000); 
}

This is the function i'm trying to implement now. But I always get a hardfault error when this function is executed. I do set the STM32 hardware for 16 bit using the CUBEMX software
3 REPLIES 3
Posted on October 12, 2015 at 18:20

So how and where is reg defined, and why not send TWO bytes instead of one?

Is the SPI in 8-bit mode or 16-bit mode, what code is generated by Cube to initialize the peripheral.

What does the system tell you in the Hard Fault Handler? If it's just a while(1) loop, consider something that better decomposes the state of the system, and what memory address exactly it's faulting on.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
marco3
Associate II
Posted on October 06, 2016 at 00:58

I'm sending two bytes together but it doesn't work. SPI is set with SPI_DATASIZE_8BIT.

uint8_t address[2] = {0xFB, 0xD8};

HAL_SPI_Transmit(&hspi1, &address, 2, 100);

it says the argument 2 of HAL_SPI_Transmit is from incompatible pointer type..how come?

michaelc.barton9
Associate II
Posted on October 06, 2016 at 10:24

because 'address' is already a pointer, so, either write it like this

HAL_SPI_Transmit(&hspi1, &address[0], 2, 100);

or like this

HAL_SPI_Transmit(&hspi1, address, 2, 100);