Jump to content
Sign in to follow this  
Oves

msp430g2452: how to send 16 bit at once?

Recommended Posts

Hi,
 
I have working code for msp430g2452 which sends data via spi as 8 bit at once.
Could somebody, please, say how to change this code to send the data as 16 bit at once?
 
Thanks a lot in advance.

#include <msp430.h> 

//
#define PIN_SCLK   BIT5 //1.5
#define PIN_DATA   BIT6 //1.6
#define PIN_CS1    BIT4 //1.4
#define PIN_CS2    BIT0 //1.0
#define PIN_RED   BIT0 //1.0

#define SELECT(PIN)  P1OUT &= ~PIN
#define DESELECT(PIN)  P1OUT |= PIN

//
#define M_DECODEMODE   0x09
#define M_INTENSITY    0x0A
#define M_SCANLIMIT    0x0B
#define M_SHUTDOWN     0x0C
#define M_DISPLAYTEST 0x0F


void matrixSet(const unsigned char address, const unsigned char value)
{
 SELECT(PIN_CS1);

 ////
 USISRL = address;
 USICNT = 8;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 ////
 USISRL = value;
 USICNT = 8;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 DESELECT(PIN_CS1);
}

void matrixInit(){
 matrixSet(M_DECODEMODE, 0x00); // BCD mode for digit decoding
 matrixSet(M_INTENSITY, 0x05); // Segment intensity
 matrixSet(M_SCANLIMIT, 0x07); // Display scan limit
 matrixSet(M_SHUTDOWN, 0x01); // Turn on the display
 matrixSet(M_DISPLAYTEST,0x00); // No test
}

void matrixClear()
{
 unsigned char x;

 for(x=1; x<9; x++)
  matrixSet(x, 0x00);
}

void matrixTest(){
 unsigned char x;

 for(x=1; x<9; x++)
  matrixSet(x, 1 << (x-1) | 1 << (7-x) );
}

void main(void) {
 
 WDTCTL  = WDTPW + WDTHOLD;            // disable WDT
 BCSCTL1  = CALBC1_16MHZ;               // 16MHz clock
 DCOCTL  = CALDCO_16MHZ;

 P1DIR   |= PIN_CS1+ PIN_CS2 + PIN_DATA + PIN_SCLK;
 DESELECT(PIN_CS1);

 //// setup SPI
 USICTL0   |= USISWRST;                     // put USI in reset mode, source USI clock from SMCLK
 USICTL0  |= USIPE5 | USIPE6 | USIPE7 | USIMST | USIOE;
 USICKCTL  |= USIDIV_0 | USISSEL_2;         // default speed 16MHz/1
 USICTL1    = USICKPH;                      // SPI_MODE_0, CPHA=0
 USICKCTL  &= ~USICKPL;       // CPOL=0
 USICTL0  &= ~USILSB;       // MSBFIRST
 USICTL0  &= ~USISWRST;           // release for operation
 ////

 ////
 matrixInit();
 matrixClear();
 matrixTest();
}

Share this post


Link to post
Share on other sites

Quickest solution, use this for matrixSet

void matrixSet(const unsigned char address, const unsigned short value)
{
 SELECT(PIN_CS1);

 //// Send address
 USISRL = address;
 USICNT = 8;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 //// Send most significant byte
 USISRL = (unsigned char)(value >> 8);
 USICNT = 8;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 //// Send least significant byte
 USISRL = (unsigned char)(value & 0xFF);
 USICNT = 8;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 DESELECT(PIN_CS1);
}

or better

void matrixSet(const unsigned char address, const unsigned short value)
{
 SELECT(PIN_CS1);

 //// Send address
 USISRL = address;
 USICNT = 8;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 //// Send word
 USISR = value;
 USICNT = USI16B | 16;
 // wait for an USICNT to decrement to 0
 while (!(USICTL1 & USIIFG));

 DESELECT(PIN_CS1);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×