Browse Source

更改成协议一致

simulating_SPI_by_software
tianjialong 2 years ago
parent
commit
1d1708dbd6
  1. 4
      app/MDK-ARM/app.uvguix.29643
  2. 28
      usersrc/usermain.c

4
app/MDK-ARM/app.uvguix.29643

@ -93,8 +93,8 @@
<flags>0</flags>
<showCmd>1</showCmd>
<MinPosition>
<xPos>-1</xPos>
<yPos>-1</yPos>
<xPos>-32000</xPos>
<yPos>-32000</yPos>
</MinPosition>
<MaxPosition>
<xPos>-1</xPos>

28
usersrc/usermain.c

@ -8,13 +8,13 @@
#define READ_CMD 0x80
#define SPI_TIMEOUT_VALUE 1000
#define SPI_CS_1() HAL_GPIO_WritePin(SEL_GPIO_Port, SEL_Pin, GPIO_PIN_SET) /* */
#define SPI_CS_0() HAL_GPIO_WritePin(SEL_GPIO_Port, SEL_Pin, GPIO_PIN_RESET) /* */
#define SPI_SCK_1() HAL_GPIO_WritePin(CLK_GPIO_Port, CLK_Pin, GPIO_PIN_SET) /* SCK = 1 */
#define SPI_SCK_0() HAL_GPIO_WritePin(CLK_GPIO_Port, CLK_Pin, GPIO_PIN_RESET) /* SCK = 0 */
#define SPI_MOSI_1() HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_SET) /* MOSI = 1 */
#define SPI_MOSI_0() HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_RESET) /* MOSI = 0 */
#define SPI_READ_MISO() HAL_GPIO_ReadPin(MISO_GPIO_Port, MISO_Pin) /* 读MISO口线状态 */
#define SPI_CS_1() HAL_GPIO_WritePin(SEL_GPIO_Port, SEL_Pin, GPIO_PIN_SET) /* */
#define SPI_CS_0() HAL_GPIO_WritePin(SEL_GPIO_Port, SEL_Pin, GPIO_PIN_RESET) /* */
#define SPI_SCK_1() HAL_GPIO_WritePin(CLK_GPIO_Port, CLK_Pin, GPIO_PIN_SET) /* SCK = 1 */
#define SPI_SCK_0() HAL_GPIO_WritePin(CLK_GPIO_Port, CLK_Pin, GPIO_PIN_RESET) /* SCK = 0 */
#define SPI_MOSI_1() HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_SET) /* MOSI = 1 */
#define SPI_MOSI_0() HAL_GPIO_WritePin(MOSI_GPIO_Port, MOSI_Pin, GPIO_PIN_RESET) /* MOSI = 0 */
#define SPI_READ_MISO() HAL_GPIO_ReadPin(MISO_GPIO_Port, MISO_Pin) /* 读MISO口线状态 */
#define Dummy_Byte 0xFF // 读取时MISO发送的数据,可以为任意数据
@ -32,8 +32,8 @@ typedef enum
uint8_t table[SPI_TYPE_NUMBER][spi_table_type_size] = {
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, // sel
{1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // sck
{1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // mosi
{1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // sck
{1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // mosi
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // miso
};
@ -77,7 +77,7 @@ void set_spi_table_sck(uint8_t startoff)
{
table[SPI_SCK_TYPE][i] = 1;
}
else if (i >= startoff && i < (startoff + 32))
else if (i >= startoff && i < (startoff + 16))
{
(clocklevel) ? (table[SPI_SCK_TYPE][i] = 1) : (table[SPI_SCK_TYPE][i] = 0);
@ -108,8 +108,8 @@ void set_spi_table_mosi(uint8_t startoff, uint8_t txdata)
}
else if ((i >= startoff + 16) && (i < (startoff + 32)))
{
table[SPI_MOSI_TYPE][i] = 0;
table[SPI_MOSI_TYPE][i + 1] = 0;
table[SPI_MOSI_TYPE][i] = 1;
table[SPI_MOSI_TYPE][i + 1] = 1;
}
else
{
@ -126,8 +126,8 @@ void dotable(uint8_t txdata)
int mosi_startoff = 4;
set_spi_table_sel(sel_startoff);
set_spi_table_sck(clock_startoff);
set_spi_table_mosi(mosi_startoff, txdata);
// set_spi_table_sck(clock_startoff);
// set_spi_table_mosi(mosi_startoff, txdata);
for (size_t i = 0; i < spi_table_type_size; i++)
{

Loading…
Cancel
Save