2015-09-29 11:14 PM
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); andchar 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 functionunsigned 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 you2015-09-30 08:19 AM
Hi h.rick,
In your original code, do you use DMA for transmission? if so, you can use the two mentioned function. If not, you have to configure DMA. After that, if you encounter any problem, you can post it. -Shahrzad-2015-09-30 02:55 PM
It was not using DMA on the original code,
but I put DMA on STM32CubeMx, MX_DMA_Init(); How can I configure DMA to work with SPI ? thanks2015-10-01 02:24 AM
Something I must change with my DMA configuration ?
2015-10-01 03:09 AM
Hi h.rick,
To configure DMA, you can use CubeMx as you have indicated. Just make sure that in the configuration view, within SPI parameter settings, you set desired DMA Settings (click Add button-Select the DMA Request- and set all other seetings). So, the generated project will contain DMA configuration. Besides, you can refer to examples using DMA within STM32Cube firmware package. -Shahrzad-2015-10-01 07:18 AM
Is my configuration correct ? thanks