Other Parts Discussed in Thread: MSP430FR6043
Hello
I have problem with reciving data from ADC`s register. The code may send commands to ADS122U04 via UART from MCU. But when I use commands from datasheet to set registers or read they value happens nothing. The code placed lower.
#include <msp430.h>
#include <msp430fr6043.h>
#include <stdio.h>
#include <stdlib.h>
// ----------------- global variable ---------------------------------------------
unsigned int rcv;
// ------------------ initialization -----------------------------------------------
void CS_init (void);
void UART_init(void);
void UART_transmit(void);
// -------------------- main ---------------------------------------------------
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
FRCTL0 = FRCTLPW | NWAITS_1;
CS_init ();
UART_init();
UART_transmit();
}
// ------------------ functions -----------------------------------------------
void CS_init (void)
{
CSCTL0_H = CSKEY_H;
CSCTL1 = DCOFSEL_3 | DCORSEL;
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;
CSCTL0_H = 0;
}
void UART_init(void)
{
P4SEL0 |= BIT1 | BIT2;
P4SEL1 |= BIT1 | BIT2; // It switch pins P4.1 and P4.2 in RX/TX mode
UCA3CTLW0 = UCSWRST; // Put eUSCI in reset
UCA3CTLW0 |= UCSSEL__SMCLK; // CLK = SMCLK
UCA3BRW = 54; // 8000000/16/9600
UCA3MCTLW |= UCOS16 | UCBRF_1 | 0x4900;
UCA3CTLW0 &= ~UCSWRST; // Initialize eUSCI
}
void UART_transmit(void)
{
UCA3TXBUF = 0x55;
while (!(UCA3IFG & UCTXIFG));
UCA3TXBUF = 0x06;
__delay_cycles(80);
// }
while (!(UCA3IFG & UCTXIFG));
// Settings reg 2
UCA3TXBUF = 0x55;
while (!(UCA3IFG & UCTXIFG));
UCA3TXBUF = 0x44;
while (!(UCA3IFG & UCTXIFG));
UCA3TXBUF = 0x40;
// Recive reg 2
while (!(UCA3IFG & UCTXIFG));
UCA3TXBUF = 0x55;
while (!(UCA3IFG & UCTXIFG));
UCA3TXBUF = 0x24;
while (!(UCA3IFG & UCTXIFG));
while (!(UCA3IFG & UCRXIFG));
rcv = UCA3RXBUF;
}