EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Interfacing MSP430 with MAX6957 LED Driver

Started by kahunwa March 17, 2013
Hello Everyone, I am trying to control a MAX6957 LED driver (via SPI communication) using my MSP430FG4618. But no luck. I searched the internet for sample code and a good application note but cannot find one. Here is my code (thanks in advance for helping:

/* MASTER SLAVE */
/* MSP430FG4618 MAX6957 */
/* ------------------ ------------------ */
/* | | | | */
/* | | | | */
/* | H7 Pin4|UCxSCLK Clock|25 | */
/* | |------------------>| | */
/* | H7 Pin3|UCxSOMI Dout|4 | */
/* | |<------------------| | */
/* | H7 Pin2|UCxSIMO Din|26 | */
/* | |------------------>| | */
/* | USCI | | Target | */
/* | SPI | __| Device | */
/* | H7 Pin1|P3.0 SS|27 | */
/* | |------------------>| | */
/* | |Px.x STE|xx | */
/* | |-------------------| | */
/* | | | | */
/* | | | | */
/* ------------------ ------------------ */
/* */

//***********************************| INCLUDE DIRECTIVES |***********************************
#include // msp430fg4618 device
//#include
//#include "include.h"

//***********************************| FUNCTION PROTOTYPES |**********************************
void SPI_Setup( void );
void write_to_MAX6957_register( char addr , char value );

//***********************************| SYMBOLIC CONSTANTS |***********************************

#define SPI_FUNCTION_SEL P3SEL //SPI peripheral module function
#define SS1 BIT0 //P3.0 -> Slave Select 1 (Active LOW) -> H7 Pin1
#define SIMO BIT1 //P3.1 -> slave in/master out of USCI_B0/SPI mode -> H7 Pin2
#define SOMI BIT2 //P3.2 -> slave out/master in of USCI_B0/SPI mode -> H7 Pin3
#define SCLK BIT3 //P3.3 -> clock outputUSCI_B0/SPI mode -> H7 Pin4

/* MAX6957 Command Address Code */
#define No-Op 0x00
#define Global_Current 0x02
#define Display_Test 0x07
#define PortConfig__P12toP15 0x0B

/* MAX6957 Register Data Address Code */
//#define Display_Test 0x07

void main (void)
{
WDTCTL = WDTPW | WDTHOLD; //Stop Watchdog Timer

SPI_Setup( );
write_to_MAX6957_register( Display_Test, Display_Test );
} /* end main function */
//***********************************| FUNCTION DECLARATIONS |**********************************
void SPI_Setup( void )
{
/* Full Four-Wire SPI => All four jumpers on H1 */
// -> 1)Initializing or Re-Configuring the USCI Module
UCB0CTL1 |= UCSWRST; //UCSWRST bit for initialization/re-configuration process
// -> 2)Initialize all USCI registers with UCSWRST=1 (including UCxCTL1)
UCB0CTL0 &= ~( UCCKPL + UC7BIT + UCMODE_0 );
// inactive state is low, 8-bit data, 3 Pin SPI
UCB0CTL0 |= UCSYNC + UCCKPH + UCMSB + UCMST;
// SPI mode, Data captured on 1st USCLK edge, changed on the following edge, MSB first, Master mode
UCB0CTL1 = UCSSEL_2; //SMSCLK

//-
// DATA RATE
// Data rate = SMSCLK/2 ~= 500kHz
// UCA0BR1 = 0x00 & UCA0BR0 = 0x02
//-
UCB0BR0 = 0x02;
UCB0BR1 = 0x00;
//-

// -> 3)Configure Ports
SPI_FUNCTION_SEL |= SIMO + SOMI + SCLK; //Signals for SPI data exchange
P3DIR |= SS1; //output direction for slave device 1

// -> 4)Clear UCSWRST via software
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

// IE2 |= UCA0TXIE + UCA0RXIE; // Enable USCI_B0 TX and RX interrupt

} /* end SPI_Setup function */

void write_to_MAX6957_register( char addr , char value )
{
P3OUT &= ~SS1; //(CS)Chip Select enable LOW, to enable slave device 1
while( P3IN & SOMI ); //wait for MAX6957 to get ready
IFG2 &= ~UCB0RXIFG; //clear flag
UCB0TXBUF = addr; //send address by puting in SPI buffer
while( !(IFG2 & UCB0RXIFG) ) //wait for Tx to finish (status byte received)
IFG2 &= ~UCB0RXIFG; //clear flag
UCB0TXBUF = value; //send data
while( !(IFG2 & UCB0RXIFG) ) //wait for Tx to finish (status byte received)
P3OUT |= SS1; //CS disable - SPI disable

} /* end write_to_MAX6957_register */

Beginning Microcontrollers with the MSP430


The 2024 Embedded Online Conference