AnsweredAssumed Answered

Reading and writing to SPI ?

Question asked by H.Rick on Sep 30, 2015
Latest reply on Oct 1, 2015 by H.Rick
Guys,

Can I replace this function

SPIPutChar(uint8_t data[])
{  
     
 
   /* Write and Read a byte on SPI interface. */
   unsigned char inb;
 
   /* Wait if TXE cleared, Tx FIFO is full. */
   while ((SPI1->SR & TXE) == 0);
   SPI1->DR = outb;
   /* Wait if RNE cleared, Rx FIFO is empty. */
   while ((SPI1->SR & RXNE) == 0);
   inb = SPI1->DR;
   return (inb);
HAL_SPI_Transmit_DMA(&hspi1,data,1);

and
char SPIGetChar(void)
{
 char Data = 0;
 
  /* Wait until the transmit buffer is empty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  /* Send the byte */
  SPI_I2S_SendData(SPI1, 0xFF);
 
  /* Wait until a data is received */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  /* Get the received data */
 /Data = SPI_I2S_ReceiveData(SPI1);
 
  /* Return the shifted data */
  return Data;
}
to :

HAL_SPI_Receive_DMA(&hspi1, data, 1)

Please correct me if I'm wrong with this function, I tried to replace with HAL function

unsigned char Mp3ReadRegister( unsigned char addressbyte)
{
     
 
    int resultvalue = 0;
    Mp3DeselectData();
    Mp3SelectControl();             //XCS = 0
    uint8_t data7[2] = { VS_READ_COMMAND, addressbyte };
    HAL_SPI_Transmit_DMA(&hspi1,data7,2);  
     
    //SPIPutChar(VS_READ_COMMAND);  //????????
    //SPIPutChar(addressbyte);      //????????
  uint8_t data8[1] = {0x00};
 
    resultvalue = HAL_SPI_Receive_DMA(&hspi1, data8, 1) << 8;
    resultvalue |= HAL_SPI_Receive_DMA(&hspi1, data8, 1);
    //resultvalue = SPIGetChar() << 8;//???8???
    //resultvalue |= SPIGetChar();      //???8???
    Mp3DeselectControl();             
    return resultvalue;             //??16??????
 
}

Thank you

Outcomes