Hello Everyone,
I am trying to communicate between AD7190 and MSP432P401M controller through SPI communication. My issue is I can't read default register value from AD7190.
I have attached circuit diagram and code for your reference.
The connections are as follows:-
Pin no 13,14 -left open
PIn no. 17 to GND
pin no 22 (SYNC') tied to 3.3V
pin no. 5,6,7,8 left open
#include "msp.h" #include "common.h" #include "AD7730.h" //**************SPI Initialization*******************// void SPI_INT() { P1->SEL0 |= BIT4 | BIT5 | BIT6 | BIT7; // set 4-SPI pin as second function EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SWRST; // Put eUSCI state machine in reset EUSCI_B0->CTLW0 = EUSCI_B_CTLW0_SWRST | // Remain eUSCI state machine in reset EUSCI_B_CTLW0_MST | // Set as SPI master EUSCI_B_CTLW0_SYNC | // Set as synchronous mode EUSCI_B_CTLW0_MSB| // MSB first EUSCI_B_CTLW0_MODE_2 | // 4-pin mode with slave enable when STE low EUSCI_B_CTLW0_STEM | // STE mode select EUSCI_B_CTLW0_SSEL__SMCLK; // SMCLK // Clock polarity initially low //data out on first rising edge //data out on first falling edge //this setting are according to AD7730 CLK_POL tie to ground or Zero EUSCI_B0->BRW = 0x01; // /2,fBitCl0ock = fBRCLK/(UCBRx+1). EUSCI_B0->CTLW0 &= ~EUSCI_B_CTLW0_SWRST; // Initialize USCI state machine } //*************SPI transmit***************** void spi_tx(uint8_t txdata) { while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG)); EUSCI_B0->TXBUF = txdata ; } //***********Function to write internal register void WriteRegister(uint8_t W_address, int N_OF_Byte, int data) { /* local variable declaration */ int var32bit=data; uint8_t var8bit1,var8bit2,var8bit3,var8bit4; var8bit1 = var32bit; // Lower Order byte var8bit2 = var32bit >> 8; var8bit3 = var32bit >> 16; var8bit4 = var32bit >> 24; // Higher Order Byte spi_tx(W_address); __delay_cycles (200); if(N_OF_Byte==1) { spi_tx(var8bit1); __delay_cycles (200); } if(N_OF_Byte==2) { spi_tx(var8bit2); __delay_cycles (200); spi_tx(var8bit1); __delay_cycles (200); } if(N_OF_Byte==3) { spi_tx(var8bit3); __delay_cycles (200); spi_tx(var8bit2); __delay_cycles (200); spi_tx(var8bit1); __delay_cycles (200); } if(N_OF_Byte==4) { spi_tx(var8bit4); __delay_cycles (200); spi_tx(var8bit3); __delay_cycles (200); spi_tx(var8bit2); __delay_cycles (200); spi_tx(var8bit1); __delay_cycles (200); } } //*************SPI Receive**************** int spi_rx() { uint8_t Data; spi_tx(0x00); //send dummy data __delay_cycles (200); // Wait till a character is received // while (!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG)); Data = EUSCI_B0->RXBUF; // Move data to a temporary buffer // Clear the receive interrupt flag // EUSCI_B0->IFG &= ~EUSCI_B_IFG_RXIFG; return Data; } //*****************function to single read internal resister**********// int ReadRegister(uint8_t R_address,int N_OF_Byte) { /* local variable declaration */ int var32bit1,var32bit2,var32bit3; spi_tx(R_address); __delay_cycles (200); if(N_OF_Byte==1) { var32bit1 = spi_rx(); return var32bit1; } else if(N_OF_Byte==2) { var32bit1=spi_rx(); // higher byte __delay_cycles (200); var32bit2=spi_rx(); // lower byte var32bit1=var32bit1<<8; var32bit1=var32bit1|var32bit2; // masking into 16 bit data return var32bit1 ; } var32bit1=spi_rx(); //higher byte __delay_cycles (200); var32bit2=spi_rx(); //middle byte __delay_cycles (200); var32bit3=spi_rx(); //lower byte var32bit1=var32bit1<<8; var32bit2=var32bit1|var32bit2; var32bit2=var32bit2<<8; var32bit3=var32bit2|var32bit3; //masking into 24 bit data return var32bit3; } //******************Read AD7730 Data*******************// int ReadData() { /* local variable declaration */ int var32bit1,var32bit2,var32bit3; var32bit1=spi_rx(); __delay_cycles (200); var32bit2=spi_rx(); __delay_cycles (200); var32bit3=spi_rx(); // data mapping var32bit1=var32bit1<<8; var32bit2=var32bit1|var32bit2; var32bit2=var32bit2<<8; var32bit3=var32bit2|var32bit3; return var32bit3; } void main(void) { STATUS_Result1 = ReadRegister(COM_READ_STATUS_REG_CMD,1); // read DAC Register default value __delay_cycles (2000); }