|
@@ -13,7 +13,7 @@
|
|
#include "max7219.h"
|
|
#include "max7219.h"
|
|
|
|
|
|
#define SPI_PORT GPIOB
|
|
#define SPI_PORT GPIOB
|
|
-#define SPI_NSS GPIO_Pin_4
|
|
|
|
|
|
+#define SPI_CS GPIO_Pin_4
|
|
#define SPI_SCK GPIO_Pin_5
|
|
#define SPI_SCK GPIO_Pin_5
|
|
#define SPI_MOSI GPIO_Pin_6
|
|
#define SPI_MOSI GPIO_Pin_6
|
|
#define SPI_PINS (SPI_SCK|SPI_MOSI)
|
|
#define SPI_PINS (SPI_SCK|SPI_MOSI)
|
|
@@ -24,9 +24,9 @@ void MAX7219_Init(void) {
|
|
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE);
|
|
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE);
|
|
/* Set the MOSI,MISO and SCK at high level */
|
|
/* Set the MOSI,MISO and SCK at high level */
|
|
GPIO_ExternalPullUpConfig(SPI_PORT, SPI_PINS, ENABLE);
|
|
GPIO_ExternalPullUpConfig(SPI_PORT, SPI_PINS, ENABLE);
|
|
- /* Configure Lock pin */
|
|
|
|
- GPIO_Init(SPI_PORT, SPI_NSS, GPIO_Mode_Out_PP_High_Fast);
|
|
|
|
- GPIO_SetBits(SPI_PORT, SPI_NSS);
|
|
|
|
|
|
+ /* Configure LOAD pin */
|
|
|
|
+ GPIO_Init(SPI_PORT, SPI_CS, GPIO_Mode_Out_PP_High_Fast);
|
|
|
|
+ GPIO_SetBits(SPI_PORT, SPI_CS);
|
|
/* Init SPI */
|
|
/* Init SPI */
|
|
SPI_Init(SPI1, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_2, SPI_Mode_Master,
|
|
SPI_Init(SPI1, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_2, SPI_Mode_Master,
|
|
SPI_CPOL_High, SPI_CPHA_2Edge, SPI_Direction_1Line_Tx, SPI_NSS_Soft, 0x00);
|
|
SPI_CPOL_High, SPI_CPHA_2Edge, SPI_Direction_1Line_Tx, SPI_NSS_Soft, 0x00);
|
|
@@ -45,8 +45,8 @@ void MAX7219_WriteData(max7219_reg_t reg, uint8_t data)
|
|
{
|
|
{
|
|
/*!< Wait wait until the completion of the transfer. */
|
|
/*!< Wait wait until the completion of the transfer. */
|
|
while (SPI_GetFlagStatus(SPI1, SPI_FLAG_BSY) == SET) {}
|
|
while (SPI_GetFlagStatus(SPI1, SPI_FLAG_BSY) == SET) {}
|
|
- /* Down LOCK pin */
|
|
|
|
- GPIO_ResetBits(SPI_PORT, SPI_NSS);
|
|
|
|
|
|
+ /* Down LOAD pin */
|
|
|
|
+ GPIO_ResetBits(SPI_PORT, SPI_CS);
|
|
|
|
|
|
/*!< Wait until the transmit buffer is empty */
|
|
/*!< Wait until the transmit buffer is empty */
|
|
while (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET) {}
|
|
while (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET) {}
|
|
@@ -62,6 +62,6 @@ void MAX7219_WriteData(max7219_reg_t reg, uint8_t data)
|
|
|
|
|
|
/*!< Wait wait until the completion of the transfer. */
|
|
/*!< Wait wait until the completion of the transfer. */
|
|
while (SPI_GetFlagStatus(SPI1, SPI_FLAG_BSY) == SET) {}
|
|
while (SPI_GetFlagStatus(SPI1, SPI_FLAG_BSY) == SET) {}
|
|
- /* Up LOCK pin */
|
|
|
|
- GPIO_SetBits(SPI_PORT, SPI_NSS);
|
|
|
|
|
|
+ /* Up LOAD pin */
|
|
|
|
+ GPIO_SetBits(SPI_PORT, SPI_CS);
|
|
}
|
|
}
|