STMicroelectronics STM8 Manual page 108

Table of Contents

Advertisement

void MAX72xx_init(void);
void MAX72xx_write(unsigned char address, unsigned char value);
MAX72xx.c
#include "MAX72xx.h"
void MAX72xx_init(void)
{
GPIO_Init(CS_port, CS_pin, GPIO_MODE_OUT_PP_HIGH_FAST);
MAX72xx_write(shutdown_reg, run_cmd);
MAX72xx_write(decode_mode_reg, 0x00);
MAX72xx_write(scan_limit_reg, 0x07);
MAX72xx_write(intensity_reg, 0x04);
MAX72xx_write(display_test_reg, test_cmd);
delay_ms(10);
MAX72xx_write(display_test_reg, no_test_cmd);
}
void MAX72xx_write(unsigned char address, unsigned char value)
{
while(SPI_GetFlagStatus(SPI_FLAG_BSY));
GPIO_WriteLow(CS_port, CS_pin);
SPI_SendData(address);
while(!SPI_GetFlagStatus(SPI_FLAG_TXE));
SPI_SendData(value);
while(!SPI_GetFlagStatus(SPI_FLAG_TXE));
GPIO_WriteHigh(CS_port, CS_pin);
}
Explanation
This time we are again using the max peripheral and CPU clock:
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
....
....
CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, ENABLE);
We also need to set the GPIOs:
#define CS_pin
#define CS_port
....
....
GPIO_DeInit(GPIOC);
GPIO_Init(CS_port, CS_pin, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(GPIOC, ((GPIO_Pin_TypeDef)GPIO_PIN_5 | GPIO_PIN_6), GPIO_MODE_OUT_PP_HIGH_FAST);
Note we can use definitions to make things meaningful. The GPIOs should be configured as fast I/Os
because SPI communication is faster than simple GPIO operations.
GPIO_PIN_4
GPIOC

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM8 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF