|
@@ -63,7 +63,7 @@ static const uint16_t nixieCathodeMap[4][10] = {
|
|
|
{0x8000, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000}
|
|
|
};
|
|
|
static const uint8_t nixieCathodeMask[4][2] = {{0xff, 0x03}, {0xfc, 0x0f}, {0xf0, 0x3f}, {0xc0, 0xff}};
|
|
|
-static uint8_t nixieTubes[SPI_BUFFER_SIZE];
|
|
|
+static uint8_t tubesBuffer[SPI_BUFFER_SIZE];
|
|
|
|
|
|
/* USER CODE END PV */
|
|
|
|
|
@@ -79,6 +79,7 @@ static void MX_TIM16_Init(void);
|
|
|
static void MX_TIM17_Init(void);
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
static void showDigit(tube_pos_t pos, uint8_t dig);
|
|
|
+static void SPI_Send(void);
|
|
|
/* USER CODE END PFP */
|
|
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
@@ -172,48 +173,39 @@ int main(void)
|
|
|
/* Start the DMA transfer from Memory to SPI1 */
|
|
|
//LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
|
|
|
/* Enable SPI Interrupts */
|
|
|
- LL_SPI_EnableIT_ERR(SPI1);
|
|
|
- LL_SPI_EnableIT_TXE(SPI1);
|
|
|
+ //LL_SPI_EnableIT_ERR(SPI1);
|
|
|
+ //LL_SPI_EnableIT_TXE(SPI1);
|
|
|
//LL_SPI_EnableIT_RXNE(SPI1);
|
|
|
//LL_SPI_EnableDMAReq_TX(SPI1);
|
|
|
/* Start SPI transfer */
|
|
|
- LATCH_DOWN;
|
|
|
+ //LATCH_DOWN;
|
|
|
LL_SPI_Enable(SPI1);
|
|
|
|
|
|
// COLOR_R(0);
|
|
|
// COLOR_G(0);
|
|
|
// COLOR_B(0);
|
|
|
+ IN15_OFF;
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Infinite loop */
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
while (1)
|
|
|
{
|
|
|
- IN15_OFF;
|
|
|
IN15_Plus;
|
|
|
- COLOR_RGB(20, 20, 20);
|
|
|
- LL_mDelay(500);
|
|
|
-
|
|
|
- IN15_OFF;
|
|
|
- IN15_Minus;
|
|
|
- COLOR_RGB(40, 40, 40);
|
|
|
+ COLOR_RGB(0, 0, 0);
|
|
|
+ SPI_Send();
|
|
|
LL_mDelay(500);
|
|
|
|
|
|
IN15_OFF;
|
|
|
- IN15_Percent;
|
|
|
- COLOR_RGB(60, 60, 60);
|
|
|
- LL_mDelay(500);
|
|
|
-
|
|
|
- IN15_OFF;
|
|
|
- IN15_P;
|
|
|
- COLOR_RGB(80, 80, 80);
|
|
|
+ COLOR_RGB(0xFF, 0x7E, 0x0); // or FFBF00
|
|
|
+ SPI_Send();
|
|
|
LL_mDelay(500);
|
|
|
/* USER CODE END WHILE */
|
|
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
- LATCH_DOWN;
|
|
|
- LL_SPI_EnableIT_TXE(SPI1);
|
|
|
- LL_SPI_Enable(SPI1);
|
|
|
+ //LATCH_DOWN;
|
|
|
+ //LL_SPI_EnableIT_TXE(SPI1);
|
|
|
+ //LL_SPI_Enable(SPI1);
|
|
|
//LL_mDelay(1);
|
|
|
|
|
|
//__WFI();
|
|
@@ -221,6 +213,25 @@ int main(void)
|
|
|
/* USER CODE END 3 */
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+static void SPI_Send(void) {
|
|
|
+ int i;
|
|
|
+
|
|
|
+ LATCH_DOWN;
|
|
|
+
|
|
|
+ for (i=0; i<SPI_BUFFER_SIZE; i++) {
|
|
|
+ // Wait for TXE 'transmit buffer empty' bit to be set.
|
|
|
+ while ( !( SPI1->SR & SPI_SR_TXE ) ); // == 0
|
|
|
+ // Send the byte.
|
|
|
+ *( uint8_t* )&(SPI1->DR) = tubesBuffer[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ while ((SPI1->SR & SPI_SR_FTLVL) != 0);
|
|
|
+ while ((SPI1->SR & SPI_SR_BSY) != 0);
|
|
|
+ LATCH_UP;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @brief Function called from SPI1 IRQ Handler when TXE flag is set
|
|
|
* Function is in charge to transmit byte on SPI lines.
|
|
@@ -232,7 +243,14 @@ void SPI1_Tx_Callback(void)
|
|
|
static int idx=0;
|
|
|
/* Write character in Data register.
|
|
|
TXE flag is cleared by reading data in DR register */
|
|
|
- LL_SPI_TransmitData8(SPI1, nixieTubes[idx]);
|
|
|
+ //LL_SPI_TransmitData8(SPI1, tubesBuffer[idx]);
|
|
|
+#if defined (__GNUC__)
|
|
|
+ __IO uint8_t *spidr = ((__IO uint8_t *)&SPI1->DR);
|
|
|
+ *spidr = tubesBuffer[idx];
|
|
|
+#else
|
|
|
+ *((__IO uint8_t *)&SPI1->DR) = TxData;
|
|
|
+#endif /* __GNUC__ */
|
|
|
+
|
|
|
idx ++;
|
|
|
|
|
|
if (idx >= SPI_BUFFER_SIZE) {
|
|
@@ -459,7 +477,7 @@ static void MX_SPI1_Init(void)
|
|
|
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
|
|
|
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
|
|
|
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
|
|
- SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
|
|
|
+ SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV256;
|
|
|
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
|
|
|
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
|
|
SPI_InitStruct.CRCPoly = 7;
|
|
@@ -940,33 +958,33 @@ static void showDigit(tube_pos_t pos, uint8_t dig)
|
|
|
|
|
|
switch (pos) {
|
|
|
case Tube_A:
|
|
|
- nixieTubes[0] = (uint8_t)nixieCathodeMap[Tube_A][dig];
|
|
|
+ tubesBuffer[0] = (uint8_t)nixieCathodeMap[Tube_A][dig];
|
|
|
|
|
|
- nixieTubes[1] &= ~nixieCathodeMask[Tube_A][1];
|
|
|
- nixieTubes[1] |= (uint8_t)(nixieCathodeMap[Tube_A][dig] >> 8);
|
|
|
+ tubesBuffer[1] &= ~nixieCathodeMask[Tube_A][1];
|
|
|
+ tubesBuffer[1] |= (uint8_t)(nixieCathodeMap[Tube_A][dig] >> 8);
|
|
|
break;
|
|
|
|
|
|
case Tube_B:
|
|
|
- nixieTubes[1] &= ~nixieCathodeMask[Tube_B][0];
|
|
|
- nixieTubes[1] |= (uint8_t)nixieCathodeMap[Tube_B][dig];
|
|
|
+ tubesBuffer[1] &= ~nixieCathodeMask[Tube_B][0];
|
|
|
+ tubesBuffer[1] |= (uint8_t)nixieCathodeMap[Tube_B][dig];
|
|
|
|
|
|
- nixieTubes[2] &= ~nixieCathodeMask[Tube_B][1];
|
|
|
- nixieTubes[2] |= (uint8_t)(nixieCathodeMap[Tube_B][dig] >> 8);
|
|
|
+ tubesBuffer[2] &= ~nixieCathodeMask[Tube_B][1];
|
|
|
+ tubesBuffer[2] |= (uint8_t)(nixieCathodeMap[Tube_B][dig] >> 8);
|
|
|
break;
|
|
|
|
|
|
case Tube_D:
|
|
|
- nixieTubes[2] &= ~nixieCathodeMask[Tube_D][0];
|
|
|
- nixieTubes[2] |= (uint8_t)nixieCathodeMap[Tube_D][dig];
|
|
|
+ tubesBuffer[2] &= ~nixieCathodeMask[Tube_D][0];
|
|
|
+ tubesBuffer[2] |= (uint8_t)nixieCathodeMap[Tube_D][dig];
|
|
|
|
|
|
- nixieTubes[3] &= ~nixieCathodeMask[Tube_D][1];
|
|
|
- nixieTubes[3] |= (uint8_t)(nixieCathodeMap[Tube_D][dig] >> 8);
|
|
|
+ tubesBuffer[3] &= ~nixieCathodeMask[Tube_D][1];
|
|
|
+ tubesBuffer[3] |= (uint8_t)(nixieCathodeMap[Tube_D][dig] >> 8);
|
|
|
break;
|
|
|
|
|
|
case Tube_E:
|
|
|
- nixieTubes[3] &= ~nixieCathodeMask[Tube_E][0];
|
|
|
- nixieTubes[3] |= (uint8_t)nixieCathodeMap[Tube_E][dig];
|
|
|
+ tubesBuffer[3] &= ~nixieCathodeMask[Tube_E][0];
|
|
|
+ tubesBuffer[3] |= (uint8_t)nixieCathodeMap[Tube_E][dig];
|
|
|
|
|
|
- nixieTubes[4] = (uint8_t)(nixieCathodeMap[Tube_E][dig] >> 8);
|
|
|
+ tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_E][dig] >> 8);
|
|
|
break;
|
|
|
|
|
|
default:
|