From c1e6196d3da930a82f12313bce04205b3488f7f1 Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期日, 24 三月 2024 09:22:59 +0800 Subject: [PATCH] Merge branch '免布线标签-lora-泰斗GPS' of http://47.108.70.204:60062/r/XRange_Tag into 免布线标签-lora-泰斗GPS --- Src/OnChipDevices/Spi.c | 84 ++++++++++++++++++++++-------------------- 1 files changed, 44 insertions(+), 40 deletions(-) diff --git a/Src/OnChipDevices/Spi.c b/Src/OnChipDevices/Spi.c index 0e7d8fd..c1422d8 100644 --- a/Src/OnChipDevices/Spi.c +++ b/Src/OnChipDevices/Spi.c @@ -20,7 +20,14 @@ /* Write to SPIx CR1 */ SPIx->CR1 = tmpreg; } - +void Uwb_CS_di() +{ + if(!HAL_GPIO_ReadPin( RADIO_NSS_GPIO_Port, RADIO_NSS_Pin)) + { + HAL_GPIO_WritePin( RADIO_NSS_GPIO_Port, RADIO_NSS_Pin,GPIO_PIN_SET); + printf("LORA_cs_error\r\n"); + } +} /*! ------------------------------------------------------------------------------------------------------------------ * Function: writetospi() * @@ -32,9 +39,9 @@ int writetospi ( uint16_t headerLength, - uint8_t *headerBuffer, + uint8_t *headerBuffer, uint32_t bodylength, - uint8_t *bodyBuffer + uint8_t *bodyBuffer ) { @@ -43,33 +50,30 @@ decaIrqStatus_t stat ; // stat = decamutexon() ; - +Uwb_CS_di(); 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; - // decamutexoff(stat) ; + // decamutexoff(stat) ; return 0; } // end writetospi() @@ -86,7 +90,7 @@ int readfromspi ( uint16_t headerLength, - uint8_t *headerBuffer, + uint8_t *headerBuffer, uint32_t readlength, uint8_t *readBuffer ) @@ -96,35 +100,35 @@ decaIrqStatus_t stat ; - // stat = decamutexon() ; + // stat = decamutexon() ; /* Wait for SPIx Tx buffer empty */ //while (port_SPIx_busy_sending()); - +Uwb_CS_di(); 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; - // decamutexoff(stat) ; + // decamutexoff(stat) ; return 0; } // end readfromspi() -- Gitblit v1.9.3