LBRY Block Explorer

LBRY Claims • bluepill-test1-dotmatrix

c5e53d2d62bf9e6f83e1f55d83bcf2f8c30b9034

Published By
Created On
16 May 2020 11:18:41 UTC
Transaction ID
Cost
Safe for Work
Free
Yes
Bluepill Dot Matrix Display Testing
This is my first test on bluepill board testing a dotmatrix array.

Music Source:
Unknown Energy by Dox | https://soundcloud.com/dox-free-music
Music promoted by https://www.free-stock-music.com
Attribution-NoDerivs 3.0 Unported (CC BY-ND 3.0)
https://creativecommons.org/licenses/by-nd/3.0/

Here is the code

`

#include
#define DEVICES 4
#define MAX7219_MODE_DECODE 0x0900
#define MAX7219_MODE_INTENSITY 0x0A00
#define MAX7219_MODE_SCAN_LIMIT 0x0B00
#define MAX7219_MODE_POWER 0x0C00
#define MAX7219_MODE_TEST 0x0F00
#define MAX7219_MODE_NOOP 0x0000
#define __SPI_CS_ENABLE__() \
do \
{ \
GPIOA->BSRR |= GPIO_BSRR_BR4; \
} while (0)
#define __SPI_CS_DISABLE__() \
do \
{ \
GPIOA->BSRR |= GPIO_BSRR_BS4; \
} while (0)

void SPI_Init(SPI_TypeDef *SPIx)
{
SPIx->CR2 |= SPI_CR2_SSOE; // SS output enable
SPIx->CR1 = 0; // Clear unwanted values from register
SPIx->CR1 |= SPI_CR1_DFF; // 16-bit data frame format
SPIx->CR1 |= SPI_CR1_MSTR; // Master device
SPIx->CR1 |= SPI_CR1_CPOL; // Clock polarity: high when idle
SPIx->CR1 |= SPI_CR1_CPHA; // Capture data on 2nd edge (rising edge)
SPIx->CR1 |= 2 << SPI_CR1_BR_Pos;
SPIx->CR1 |= SPI_CR1_SPE; // Peripheral enabled
}

void SPI_Transmit(SPI_TypeDef *SPIx, uint16_t data)
{
while ((SPIx->SR & SPI_SR_BSY))
; // BSY=1: SPI is busy in communication
while ((SPIx->SR & SPI_SR_TXE) == 0)
; // TXE=0: Tx buffer not empty

SPIx->DR = data;

while ((SPIx->SR & SPI_SR_TXE) == 0)
;
while ((SPIx->SR & SPI_SR_BSY))
;
}
void GPIO_SPI_Init()
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;

/* PA4 software slave select */
GPIOA->CRL &= ~GPIO_CRL_CNF4; // 00: General purpose output push-pull
GPIOA->CRL |= GPIO_CRL_MODE4; // 11: Output mode, max speed 50 MHz.

/* PA5 SPI clock */
GPIOA->CRL &= ~GPIO_CRL_CNF5;
GPIOA->CRL |= GPIO_CRL_CNF5_1; // 10: Alternate function output Push-pull
GPIOA->CRL |= GPIO_CRL_MODE5; // 11: Output mode, max speed 50 MHz.

/* PA6 SPI MISO */
GPIOA->CRL &= ~GPIO_CRL_CNF6;
GPIOA->CRL |= GPIO_CRL_CNF6_1; // 10: Alternate function output Push-pull
GPIOA->CRL |= GPIO_CRL_MODE6; // 11: Output mode, max speed 50 MHz.

/* PA7 SPI MOSI */
GPIOA->CRL &= ~GPIO_CRL_CNF7;
GPIOA->CRL |= GPIO_CRL_CNF7_1; // 10: Alternate function output Push-pull
GPIOA->CRL |= GPIO_CRL_MODE7; // 11: Output mode, max speed 50 MHz.

/* Remap AFIO */
AFIO->MAPR &= ~AFIO_MAPR_SPI1_REMAP; // 0: No remap (NSS/PA4, SCK/PA5, MISO/PA6, MOSI/PA7)
}

void GPIO_LED_Init()
{
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
/* PC13 on-board LED */
GPIOC->CRH &= ~GPIO_CRH_CNF13; // 00: General purpose output push-pull
GPIOC->CRH |= GPIO_CRH_MODE13; // 11: Output mode, max speed 50 MHz.
}

void setConfig(uint16_t settings, uint8_t value)
{
__SPI_CS_ENABLE__();
for (int i = 0; i < DEVICES; i++)
{
SPI_Transmit(SPI1, settings | value);
}
__SPI_CS_DISABLE__();
}

void clear_display()
{
uint16_t col;
int bit;

for (col = 0x100; col <= 0x800; col += 0x100)
{
for (bit = 0; bit < 8; bit++)
{
__SPI_CS_ENABLE__();
for (int i = 0; i < 4; i++)
{
SPI_Transmit(SPI1, col | (0 << bit & 0xFF));
}
__SPI_CS_DISABLE__();
}
}
}
void setup()
{
// put your setup code here, to run once:
SystemCoreClockUpdate();
HAL_Init();

// Setup GPIOs
GPIO_LED_Init();
GPIO_SPI_Init();
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
SPI_Init(SPI1);

// CS inactive
__SPI_CS_DISABLE__();

// Init MAX7219
setConfig(MAX7219_MODE_SCAN_LIMIT, 7);
setConfig(MAX7219_MODE_INTENSITY, 0x03);
setConfig(MAX7219_MODE_POWER, 0x1);
setConfig(MAX7219_MODE_DECODE, 0);
setConfig(MAX7219_MODE_TEST, 0);
clear_display();
}

void loop()
{

HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);

for (int j = 0; j < 8; j++)
{
for (int k = 0x100; k <= 0x800; k += 0x100)
{
__SPI_CS_ENABLE__();
for (int i = 0; i < 4; i++)
{
SPI_Transmit(SPI1, k | (1 << j & 0xFF));
}
__SPI_CS_DISABLE__();
}
HAL_Delay(100);
}



for (int j = 7; j >= 0; j--)
{
for (int k = 0x100; k <= 0x800; k += 0x100)
{
__SPI_CS_ENABLE__();
for (int i = 0; i < 4; i++)
{
SPI_Transmit(SPI1, k | (1 << j & 0xFF));
}
__SPI_CS_DISABLE__();
}
HAL_Delay(100);
}


for (int k = 0x100; k <= 0x800; k += 0x100)
{
__SPI_CS_ENABLE__();
for (int i = 0; i < 4; i++)
{
SPI_Transmit(SPI1, k | (0x00 & 0xFF));
}
__SPI_CS_DISABLE__();
}

for (int k = 0x100; k <= 0x800; k += 0x100)
{
__SPI_CS_ENABLE__();
for (int i = 0; i < 4; i++)
{
SPI_Transmit(SPI1, k | (0xFF & 0xFF));
}
__SPI_CS_DISABLE__();
HAL_Delay(100);
__SPI_CS_ENABLE__();
for (int i = 0; i < 4; i++)
{
SPI_Transmit(SPI1, k | (0x00 & 0xFF));
}
__SPI_CS_DISABLE__();
}

}
`
Author
Content Type
Unspecified
video/mp4
Language
English
Open in LBRY

More from the publisher

VIDEO
LOGIS
LOGIS
VIDEO
MY NA
VIDEO
MY RA
VIDEO
MY FI
VIDEO
CAN Y
VIDEO
SPACE
VIDEO
MY FL
VIDEO
MY FL