yincheng.zhong
2024-03-24 dbe010cbc556a3f07136b7eac67e62f115285db8
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,7 +50,7 @@
    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);
@@ -51,8 +58,8 @@
//      delay_ms(1);
    for(i = 0; i < headerLength; i++)
    {
            SPIx->DR= headerBuffer[i];
        while ((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET);
        SPIx->DR= headerBuffer[i];
        while ((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET);
        SPIx->DR;
    }
@@ -60,13 +67,13 @@
    for(i = 0; i < bodylength; i++)
    {
        SPIx->DR = bodyBuffer[i];
           while ((SPIx->SR & SPI_FLAG_RXNE) == (uint16_t)RESET);
        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()
@@ -83,7 +90,7 @@
int readfromspi
(
    uint16_t       headerLength,
     uint8_t *headerBuffer,
    uint8_t *headerBuffer,
    uint32_t       readlength,
    uint8_t       *readBuffer
)
@@ -93,11 +100,11 @@
    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);
@@ -121,7 +128,7 @@
    SPIx_CS_GPIO->BSRR = SPIx_CS;
   // decamutexoff(stat) ;
    // decamutexoff(stat) ;
    return 0;
} // end readfromspi()