MAX7219, 8-digit 7 segment LED display SPI programming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-05 10:32 AM
Could some one help me in making SPI C-program of MAX7219, 8 digit 7 segment display using STM32F401RE
.
i have written this code in arm keil (µVision 5) it is not working, could someone help me please:
#include"stm32f4xx.h"
#include<stdio.h>
#include<string.h>
void Led_write (char data);
void delayMs(int n);
int main (void)
{
char num[] = {0x7e,0x60,0x6d,0x78,0x33,0x5b,0x5f,0x70,0x7f,0x7b};
RCC->AHB1ENR |= 0x0001;
RCC->AHB2ENR |= 0x1000;
GPIOA->MODER &= ~0xcf00;
GPIOA->MODER |= 0x8900;
GPIOA->AFR[0] &= ~0xf0f00000;
GPIOA->AFR[0] |= 0x50500000;
SPI1->CR1 = 0x031c;
SPI1->CR2 = 0x00;
SPI1->CR1 |= 0x40;
while(1)
{
for(int i=0;i<10;i++)
{
Led_write(num[i]);
delayMs(100);
}
}
}
void Led_write (char data)
{
while(!(SPI1->SR & 2));
GPIOA->BSRR = 0x00100000;
SPI1->DR = 0x0900 | data;
while(SPI1->SR & 0x80);
GPIOA->BSRR = 0x00000010;
}
void delayMs(int n)
{
for (int i=0;i<n;i++)
for (int j=0;j<3195;i++);
}
- Labels:
-
SPI
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-05 04:53 PM
You need to enable SPI clock in RCC.
It's probably better to use the symbols defined in the device header, rather than numbers, for the various register bitfields values.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-18 08:16 AM
hello,
I have enable the SPI1 clock in RCC using RCC->AHB2ENR |= 0x1000; using this statement.
and i have tried new code, Please help me.
/* Micro controller: STM32F401RE
PA7 DIN
PA5 SCK
PA4 SS
driver MAX7219: 8 digit 7 segment display */
#include"stm32f4xx.h"
#include<stdio.h>
void init_SPI1 (void); // initialization of SPI1
void write_SPI1 (uint16_t data); // writing data to SPI1
void delayMs (uint16_t n); // generating delay
uint16_t shut_Addr = 0x0c00; //Normal operation
uint16_t norm_Addr = 0x0c01; //Normal operation
uint16_t intn_Addr = 0x0a05; //intensity register
//uint16_t code_Addr = 0x0900; //address of decode mode
uint16_t dig1_Addr = 0x0100; //selecting digit 1
int main (void)
{
init_SPI1();
write_SPI1(norm_Addr);
write_SPI1(intn_Addr); // for intensity: intensity is 0x0e
while(1)
{
write_SPI1 (dig1_Addr | 0x01); // for DIGIT1: sending value 3
}
}
void write_SPI1 (uint16_t data) //writing something to MAX7219
{
while(!(SPI1->SR & 0x02)); //wait until transfer buffer empty
GPIOA->BSRR = 0x00100000; //Slave select = 0
SPI1->DR = data;
while(SPI1->SR & 0x80); //wait for transmission done
GPIOA->BSRR = 0x00000010; //Slave select = 1
}
void init_SPI1(void) //initializing the MAX7219
{
RCC->AHB1ENR |= 0x0001; //Enabling clock of GPIOA
RCC->APB2ENR |= 0x1000; //Enabling clock of SPI1
GPIOA->MODER &= ~0xcf00; //resetting PA5, PA7: Alternate function and PA4: output function
GPIOA->MODER |= 0x8900; //set PA5, PA7: Alternate function and PA4: output function
GPIOA->AFR[0] &= ~0xf0f00000;
GPIOA->AFR[0] |= 0x50500000; //set PA5, PA7: Alternate function
SPI1->CR1 = 0x0b14; //seting baudrate, 16 bit format
SPI1->CR2 = 0x0000;
SPI1->CR1 |= 0x0040; //Enabling SPI1
}
void delayMs(uint16_t n) //generting of delay in n ms
{
for (int i=0; i<n; i++)
for (int j=0; j<3195; i++);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-07-18 08:18 AM
Following code is attached for reference