msp430g2231 16 bit spi communication with mcp4812

Status
Not open for further replies.

mikrosen

New Member
hi..

..i am a beginner and i tried to interface a msp430g2231 ic with the dac mcp 4812 in spi communication i gave the hardware connection as below

msp430g2231 - mcp4812

P1.6------> SDI

P1.5------>SCK

P2.6------>CS

GND---->LDAC

and please check my code and tell me the mistakes.

#include <msp430g2221.h>


void main(void)
{
volatile unsigned int i,val;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x10; // P1.4 set, else reset
P1REN |= 0x10; // P1.4 pullup
P1DIR = 0x01; // P1.0 output, else input
P2DIR = 0xFF;
P2SEL =0x00;
P2OUT |= BIT6;
USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
USICTL1 |= USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_4 + USISSEL_2; // /16 SMCLK
USICTL0 &= ~USISWRST;
// USI released for operation
while(1)
{

val = 0x3FF3; // init-load data

P2OUT &= ~BIT6; // reset cs

while(!(USIIFG & USICTL1));

USISRL = val >> 8;

USICNT = 8; // USI released for operation
//write LSB

while(!(USIIFG & USICTL1));

USISRL = val;

USICNT = 8;

for (i = 0xFFF; i > 0; i--); // Time for slave to ready
P2OUT |= BIT6; // set cs
USICNT = 8;


}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…