Part Number: MSP432P401R
Hi ,
I use the spi of the Launchpad to connect to the MAX7219.
This is my hardware connection:
I am using three pins p9.4, p9.5 and p9.7.
Below is my source code.
#include "msp.h"
#include <stdint.h>
#include "Clock.h"
#include "string.h"
#include "driverlib.h"
void SPI_INIT(void)
{
EUSCI_A3->CTLW0 = 0x0001; // hold the eUSCI module in reset mode
EUSCI_A3->CTLW0 = 0xAD83; //a
EUSCI_A3->BRW = 120;
// modulation is not used in SPI mode, so clear UCA3MCTLW
EUSCI_A3->MCTLW = 0;
P9->SEL0 |= 0xB0;
P9->SEL1 &= ~0xB0;// configure P9.7, P9.5, and P9.4 as primary module function
EUSCI_A3->CTLW0 &= ~0x0001; // enable eUSCI module
EUSCI_A3->IE &= ~0x0003; // disable interrupts
}
void Write_Max7219_byte(uchar DATA)
{
while(EUSCI_A3->STATW & 0x01);
while((EUSCI_A3->IFG & 0x02))
EUSCI_A3->TXBUF = DATA;
}
void Write_Max7219(uchar address,uchar dat)
{
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
}
void Init_MAX7219(void)
{
Write_Max7219(0x09, 0x00);
Write_Max7219(0x0a, 0x03);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
}
void clear(void)
{
Write_Max7219(0x01,0x00);
Write_Max7219(0x02,0x00);
Write_Max7219(0x03,0x00);
Write_Max7219(0x04,0x00);
Write_Max7219(0x05,0x00);
Write_Max7219(0x06,0x00);
Write_Max7219(0x07,0x00);
Write_Max7219(0x08,0x00);
}
/**
* main.c
*/
void main(void)
{
unsigned char test_buf[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
WDT_A_holdTimer();
Clock_Init48MHz();
SPI_INIT();
uint i,j;
Clock_Delay1ms(50);
Write_Max7219(0x0f,0x01);
Clock_Delay1ms(1000);
Write_Max7219(0x0f,0x00);
Clock_Delay1ms(50);
Init_MAX7219();
Clock_Delay1ms(50);
clear();
Clock_Delay1ms(1000);
while(1){
for(i = 0;i < 8;i++){
Write_Max7219(i+1,test_buf[i]);
}
if(i == 8)
i = 0;
}
}
I do not use interrupts, directly manipulate registers to control data transmission.
But when I send the character array "test_buf", the first five data are ok, and the last three send past results errors.
When I execute to Write_Max7219 (6,0x04), the result from the digital tube is the execution of Write_Max7219 (6,0x04) and Write_Max7219 (8,0x06).
I suspect that after the TXBUF data is transferred to the transmit shift register, the shift register is not cleared when the next data is sent.
Because I used CCS debugging to see that the value of the TXBUF register is the same as what I wrote.
How can I tell if something is causing this error, or can I manually clear the transmit shift register to eliminate the effects of the shift register?
Thanks,
Better

