From 2dc1bee464dd15e88e9efc7f71bd4052bb71262e Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期六, 19 三月 2022 21:08:29 +0800 Subject: [PATCH] 1 --- Src/OnChipDevices/Spi.c | 75 +++++++++++++++---------------------- 1 files changed, 30 insertions(+), 45 deletions(-) diff --git a/Src/OnChipDevices/Spi.c b/Src/OnChipDevices/Spi.c index 0e7d8fd..36f193a 100644 --- a/Src/OnChipDevices/Spi.c +++ b/Src/OnChipDevices/Spi.c @@ -29,13 +29,7 @@ * returns 0 for success, or -1 for error */ uint8_t tt; -int writetospi -( - uint16_t headerLength, - uint8_t *headerBuffer, - uint32_t bodylength, - uint8_t *bodyBuffer -) +int writetospi(uint16_t headerLength, const uint8_t *headerBuffer, uint16_t bodylength, const uint8_t *bodyBuffer) { int i = 0; @@ -46,26 +40,23 @@ SPIx_CS_GPIO->BRR = SPIx_CS; // delay_ms(1); - tt=HAL_SPI_Transmit(&hspi1,headerBuffer,headerLength,10); - tt=HAL_SPI_Transmit(&hspi1,bodyBuffer,bodylength,10); +// tt=HAL_SPI_Transmit(&hspi1,headerBuffer,headerLength,10); +// tt=HAL_SPI_Transmit(&hspi1,bodyBuffer,bodylength,10); // delay_ms(1); -// for(i = 0; i < headerLength; i++) -// { -// SPIx->DR = headerBuffer[i]; + for(i = 0; i < headerLength; i++) + { + SPIx->DR= headerBuffer[i]; + while ((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); + SPIx->DR; -// while ((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); + } -// SPIx->DR ; -// } - -// for(i = 0; i < bodylength; i++) -// { -// SPIx->DR = bodyBuffer[i]; - -// while((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); - -// SPIx->DR ; -// } + for(i = 0; i < bodylength; i++) + { + SPIx->DR = bodyBuffer[i]; + while ((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); + SPIx->DR ; + } SPIx_CS_GPIO->BSRR = SPIx_CS; @@ -83,13 +74,7 @@ * returns the offset into read buffer where first byte of read data may be found, * or returns -1 if there was an error */ -int readfromspi -( - uint16_t headerLength, - uint8_t *headerBuffer, - uint32_t readlength, - uint8_t *readBuffer -) +int readfromspi(uint16_t headerLength, /*const*/ uint8_t *headerBuffer, uint16_t readlength, uint8_t *readBuffer) { int i = 0; @@ -102,25 +87,25 @@ //while (port_SPIx_busy_sending()); SPIx_CS_GPIO->BRR = SPIx_CS; - HAL_SPI_Transmit(&hspi1,headerBuffer,headerLength,10); - HAL_SPI_Receive(&hspi1,readBuffer,readlength,10); -// for(i = 0; i < headerLength; i++) -// { -// SPIx->DR = headerBuffer[i]; +// HAL_SPI_Transmit(&hspi1,headerBuffer,headerLength,10); +// HAL_SPI_Receive(&hspi1,readBuffer,readlength,10); + for(i = 0; i < headerLength; i++) + { + SPIx->DR = headerBuffer[i]; -// while((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); + while((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); -// readBuffer[0] = SPIx->DR ; // Dummy read as we write the header -// } + readBuffer[0] = SPIx->DR ; // Dummy read as we write the header + } -// for(i = 0; i < readlength; i++) -// { -// SPIx->DR = 0; // Dummy write as we read the message body + for(i = 0; i < readlength; i++) + { + SPIx->DR = 0; // Dummy write as we read the message body -// while((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); + while((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET); -// readBuffer[i] = SPIx->DR ;//port_SPIx_receive_data(); //this clears RXNE bit -// } + readBuffer[i] = SPIx->DR ;//port_SPIx_receive_data(); //this clears RXNE bit + } SPIx_CS_GPIO->BSRR = SPIx_CS; -- Gitblit v1.9.3