cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with SPI transmission on G071

BerndE
Associate II

Hi,

I am having problems sending a part of an array with SPI. It is no problem to send 4 Bytes from the beginning of the array, but if I want to send 4 Bytes from another starting position (for example: start from tmp[1]) it does not work. In this case I can see on the oscilloscope that the command and the address are transmitted and after that comes nothing.

Any ideas??

uint8_t tmp[6] = {6,1,6,1,5,5};

  uint8_t *ptr = &tmp[0];

  uint8_t *ptr2;

  uint8_t command = 0, len=4, address = 0x07;

  ptr2 = &tmp[1];

  HAL_GPIO_WritePin(SPISSN_GPIO_Port, SPISSN_Pin, RESET);

   // Write & Length

   command = 0x80 | (len & 0x7F);

   HAL_SPI_Transmit(&hspi2, (uint8_t*)(&command), 1, 100);

   //address

   HAL_SPI_Transmit(&hspi2, (uint8_t*)(&address), 1, 100);

   //send "len" bytes of data

   HAL_SPI_Transmit(&hspi2, tmp, len, 100); //ok

   

HAL_SPI_Transmit(&hspi2, ptr, len, 100); //ok

   

HAL_SPI_Transmit(&hspi2, ptr2, len, 100); //NOT ok

   HAL_GPIO_WritePin(SPISSN_GPIO_Port, SPISSN_Pin, SET);

Kind regards,

Bernd

5 REPLIES 5
wuio
Associate II

When you send ptr2, do you have a clock signal and the data is bad or does nothing happen at all?

S.Ma
Principal

First try with 8 bit mode spi and 8 bit dma transfer to make sure it is not a odd memory alignment issue.

BerndE
Associate II

Clock signal is ok until address is sent, after this nothing happens.

I am using 8 bit spi mode.

Strange is, that nothing happens after the address, no wrong values.

This is a documented behaviour - if you provide a halfword-unaligned address and request to trnasfer more than a byte, Cube/HAL attempts to read a halfword from the memory and that leads to hardfault on Cortex-M0/M0+.

This is from CubeF0 but I guess the same you'll find in CubeG0 too:

     (#) In case more than 1 byte is requested to be transferred, the HAL SPI uses 16-bit access for data buffer.
          But there is no support for unaligned accesses on the Cortex-M0 processor.
          So, if the user wants to transfer more than 1 byte, it shall ensure that 16-bit aligned address is used for:
          (##) pData parameter in HAL_SPI_Transmit(), HAL_SPI_Transmit_IT(), HAL_SPI_Receive() and HAL_SPI_Receive_IT()
          (##) pTxData and pRxData parameters in HAL_SPI_TransmitReceive() and HAL_SPI_TransmitReceive_IT()

JW

BerndE
Associate II

It seems to be the same behaviour, but it is not documented. As a workaround, I will copy the data into a temp. array and send the data from this array.

Kind regards,

Bernd