Created
April 4, 2015 13:51
-
-
Save JulioAlexanderAguilarAngulo/2265895c9f88bddb32e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
STM32 microcontrollers Course | |
Author: Julio Alexander Aguilar Angulo | |
Contents: Useful routines to implement control a MAX7219 spi controller without the use of the spi peripheral | |
( All is based on loops and masking!!) [it's up to you to do the rest !!! good luck] | |
***/ | |
// declarations based on the ISEN32 board hardware: portA | |
#define ckmask 1<<5; | |
#define datmask 1<<7; | |
#define max7219load 1<<8; | |
#define Chip_Load GPIOA->BSRRH |= max7219load; //%10000000; CS=0 | |
#define Chip_UnLoad GPIOA->BSRRL |= max7219load; //%01111111; CS=1 | |
//------------------ | |
void SendData(uint8_t data) | |
{ | |
uint8_t LOOP, FLAG; | |
GPIOA->BSRRH |= ckmask;//SH_CLK = 0; | |
for (LOOP=0; LOOP<8; LOOP++){ | |
GPIOA->BSRRH |= 1<<5;//SH_CLK = 0; | |
FLAG=data&0x80;//because max7219 need MSb first !! | |
if(FLAG==0){ GPIOA->BSRRH |= datmask;}// data=0 | |
else { GPIOA->BSRRL |= datmask;}// data=1 | |
data <<= 1; | |
GPIOA->BSRRL |= ckmask;//SH_CLK = 1; | |
//delay(); | |
} | |
} | |
static void SPI_write(uint8_t add, uint8_t data) | |
{ | |
Chip_UnLoad;//1 | |
Chip_Load;//0 | |
SendData(add); | |
SendData(data); | |
Chip_UnLoad;//1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment