cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert data coming from SPI

ATeli.1
Associate III

Hi, I connect X-NUCLEO-CCA02M1 to my NUCLEO-F401RE. I am using SPI1 for the communication between devices. For what I have understood the function below convert N bit (for me N = 8) in a integer. Since i want to stream via UART those bit how can i process the data?

HAL_SPI_Receive_DMA(&hspi1, (uint8_t*)rx_buffer, BUFFER_SIZE);

To enable the data processing I am using this callback

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi){
  dataReadyflag = 1;
}

And then I am checking in the while loop is possible to start data processing as shown

 /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    if(dataReadyflag == 1){
      process_data();
      send_data();
      dataReadyflag = 0;
    }
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }

I am thinking that maybe is possible to read the data from SPI before conversion in some register. Is this possible?

2 REPLIES 2

Convert it to what exactly?

You can push bytes of data over all manner of interfaces, provided you have sufficient bandwidth, and presumably with some knowledge about how the data is framed, and what information it encodes.

The larger the buffer, the higher the latency will be between you receiving the data, and subsequently dispatching it.

As this is likely to be a continuous process you'll want to manage multiple active data buffers, and have the receiver and transmit operations occur concurrently. ie you typically don't want to be overwriting the buffer you're trying to send.

If you're using DMA you should be able to track the progress of the transfer, and inspect the memory that's already been filled.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ATeli.1
Associate III

Thank you for your help. In this case I am trying to read the data coming from the SPI in packet of 8 bit. For what I understood the SPI function convert 8 bit in 1 byte integer and store it in the buffer.

Since I need to reconstruct a PDM signal, to be able to reconstruct the PCM signal, to send both via UART, I am thinking in which way can I effectively do this.

I am sorry if some questions are redundant but I am new in this world. Thank you very much​