Tool/software: Code Composer Studio
Hello,
I receive only 0x00 data in UCB0RXBUF from an AD7689 adc, and i don't know why. I would like to get datas from a pressure sensor.
My code is:
#include <msp430.h>
char spiReadByte(void);
/*
* main.c
*/
int main(void) {
int i;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR=BIT0; // make pin 0 output
P1OUT=BIT0; // make pin 0 high
P2DIR=BIT0+BIT1;
P2OUT=0;
P3OUT = 0x40; // Set slave reset
P3DIR |= 0x40; //
P3SEL |= 0x0E; // P3.0,1,2,3 USCI_B0 option select
UCB0CTL0 |= UCCKPL | UCMSB | UCMST | UCSYNC; // 3-pin, 8-bit SPI master
UCB0CTL1 |= UCSSEL_2; // SMCLK
UCB0BR0 |= 0x02; // /2
UCB0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCB0RXIE; // Enable USCI0 RX interrupt
P3OUT &= ~0x40; // Now with SPI signals initialized,
P3OUT |= 0x40; // reset slave
for (i = 50; i > 0; i--); // Wait for slave to initialize -
for(i=2; i>0; i--) //DIN-t 2 beszélgetésig high-ba
{spiReadByte();}
//while (!(IFG2 & UCB0TXIFG));
//UCB0TXBUF = /*config adc hexaba*/; // Transmit first character
//printf("%d\n", spiReadByte());
while(1)
{spiReadByte();}
}
char spiReadByte(void)
{
char adat;
// wait for tx
while (!(IFG2 & UCB0TXIFG)); // This only tells you when the TX buffer is empty.
UCB0TXBUF = 0xAA;
while (!(IFG2 & UCB0RXIFG));
adat=UCB0RXBUF;
return adat;
}