Let user manually use SS_Set and SS_Clr
This commit is contained in:
parent
e129b212f5
commit
b56448d008
21
softspi.c
21
softspi.c
@ -54,14 +54,21 @@ HAL_StatusTypeDef SoftSPI_Init(SoftSPI_TypeDef *SoftSPIx)
|
|||||||
return HAL_OK;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoftSPI_SetSS(SoftSPI_TypeDef *SoftSPIx)
|
||||||
|
{
|
||||||
|
SS_Set;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftSPI_ClrSS(SoftSPI_TypeDef *SoftSPIx)
|
||||||
|
{
|
||||||
|
SS_Clr;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte)
|
uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte)
|
||||||
{
|
{
|
||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
// Select Device
|
|
||||||
SS_Clr;
|
|
||||||
|
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
SCLK_Clr;
|
SCLK_Clr;
|
||||||
@ -85,9 +92,6 @@ uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte)
|
|||||||
Delay;
|
Delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unselect Device
|
|
||||||
SS_Set;
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,9 +101,6 @@ void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *
|
|||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
uint8_t i, j;
|
uint8_t i, j;
|
||||||
|
|
||||||
// Select Device
|
|
||||||
SS_Clr;
|
|
||||||
|
|
||||||
for (j = 0; j < len; j++)
|
for (j = 0; j < len; j++)
|
||||||
{
|
{
|
||||||
data = 0;
|
data = 0;
|
||||||
@ -131,8 +132,6 @@ void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *
|
|||||||
pRead[j] = data;
|
pRead[j] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unselect Device
|
|
||||||
SS_Set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t SoftSPI_GPIOx_Pin_Init(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode, uint32_t Pull)
|
uint8_t SoftSPI_GPIOx_Pin_Init(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode, uint32_t Pull)
|
||||||
|
|||||||
@ -12,8 +12,8 @@
|
|||||||
#include "softspi_conf.h"
|
#include "softspi_conf.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SoftSPI Structure definition
|
* @brief SoftSPI Structure definition
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GPIO_TypeDef *SCLK_GPIO;
|
GPIO_TypeDef *SCLK_GPIO;
|
||||||
@ -33,6 +33,9 @@ typedef struct
|
|||||||
|
|
||||||
HAL_StatusTypeDef SoftSPI_Init(SoftSPI_TypeDef *SoftSPIx);
|
HAL_StatusTypeDef SoftSPI_Init(SoftSPI_TypeDef *SoftSPIx);
|
||||||
|
|
||||||
|
void SoftSPI_SetSS(SoftSPI_TypeDef *SoftSPIx);
|
||||||
|
void SoftSPI_ClrSS(SoftSPI_TypeDef *SoftSPIx);
|
||||||
|
|
||||||
uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte);
|
uint8_t SoftSPI_WriteRead(SoftSPI_TypeDef *SoftSPIx, uint8_t byte);
|
||||||
|
|
||||||
void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *pRead, uint32_t len);
|
void SoftSPI_WriteReadBuff(SoftSPI_TypeDef *SoftSPIx, uint8_t *pWrite, uint8_t *pRead, uint32_t len);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user