PIC32MX and MAX7219

Thread Starter

dacarvalho

Joined Oct 27, 2017
12
First of all, sorry for my poor english... I have a little of experience with pic32 but, i am stuck trying to operate a max7219 that drives a 8x8 led matrix, like this one https://www.elabpeers.com/max7219-8x8-dot-led-matrix-display.html .
The problem is: i know that i need to configure SPI module in order to communicate with max7219, but until now i got nothing. my board is MAX32 from Digilent with a PIC32MX795F512L.
I know that i have 8 bits for data 4 bits to address and other 4 are irrelevant, like this:

Post image
Ill post my code here:
-----------------------------------
SPI Init
void spiInit(){
SPI2CONbits.ON = 0; // Disable SPI2
SPI2CONbits.CKP = 1; // IDLE state as 0
SPI2CONbits.CKE = 0; // Clock active transition from 1 to 0
SPI2CONbits.SMP = 0;
SPI2CONbits.MODE16 = 1; // Use 16 bit SPI interface
SPI2CONbits.MODE32 = 0; // Use 32 bit SPI interface
SPI2CONbits.ENHBUF = 0; // Enable TX/RX
SPI2CONbits.MSTEN = 1; // Enable master mode
SPI2STATbits.SPIROV = 0; // Clear overflow error flag
SPI2BRG = 4;
SPI2CONbits.ON = 1; // Enable SPI2 module
}
-----------------------------------
MAX7219 Send Data
void maxWrite(uint16_t address, uint8_t data){
uint16_t dataToSend = 0x0000;
address = address & 0x000F; // Limit address to 4 bits
data = data & 0x00FF; // Limit data to 8 bits
dataToSend = (0x0 << 12) | (address << 8) | data;
SPI2BUF = dataToSend; // Info to max7219 module
while(SPI2ASTATbits.SPIRBE); // Wait while SPI is sending info
}

Can someone else please help me :) Thanks
 

nsaspook

Joined Aug 27, 2009
13,308
Is the SPI interface actually sending data in the needed mode format with the proper clocks to the device. If that's true then you need to read the device datasheet for the correct sequence of programming bytes for it to function correctly. I would send the code for Display Test 0xXF as my test sequence as all zeros is a No-Op 0xX0. Wish I could help more but I don't have your hardware locally.
 
Top