Hi, I'm trying to run an ADS1248 with a MSP430F5438 for my university project, but I'm having some problems. I've done the initialization functions with the TI examples and an ADS1248 application code that I've found in the forum. Here is my code:
Here are my files:
/* * ads1248.c */ #include "msp430x54x.h" #include "ads1248.h" // Global variables unsigned char regreadads[15]; //Tabla con los registros de control del AD unsigned char regwriteads[15]; //Tabla con los registros de control del AD // Functions void ADS1248AssertCS(int fAssert) { if (fAssert) P9OUT &= !(ADS1248_CS); else P9OUT |= ADS1248_CS; } int ADS1248SendResetCommand(void) { char dummy; // assert CS to start transfer ADS1248AssertCS(1); // CS goes low // send the command byte while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = ADS1248_CMD_RESET; while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; // de-assert CS ADS1248AssertCS(0); // CS goes high __delay_cycles(48000); //0.6ms pause -> oscF*0.6ms=8Mhz*0.6ms = 128000 (as specified in datasheet) return 0; } //Lee u void ADS1248ReadData(int* dato) { char dummy; // assert CS to start transfer ADS1248AssertCS(1); // CS goes low //Waiting for DRDY low while(P9IN & ADS1248_DRDY); //RDATA command is sent while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = ADS1248_CMD_RDATA; while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; __delay_cycles(20); //Pause //Read 24 bits data UCB2TXBUF = 0xff; while(!(UCB2IFG & UCRXIFG)); *dato = UCB2RXBUF; //MSB UCB2TXBUF = 0xff; while(!(UCB2IFG & UCRXIFG)); *(dato++) = UCB2RXBUF; //Mid-Byte UCB2TXBUF = 0xff; while(!(UCB2IFG & UCRXIFG)); *(dato++) = UCB2RXBUF; //LSB ADS1248AssertCS(0); // CS goes high } int initSPIads1248(void) { //Configuraci�n del puerto 9: //P9.1 UCB2SIMO -> Master Output //P9.2 UCB2SOMI -> Master Input //P9.3 UCB2CLK -> Clock //P9.0 O -> ADS1248_CS, activate at low level //P9.6 O -> ADS1248_START //P9.7 I <- ADS1248_DRDY P9SEL |= 0x0E; P9DIR |= 0x41; //P8.7 O -> ADS1248_RESET, activate at low level P8SEL |= 0x00; P8DIR |= 0x80; //8 bit, MSB first, synchronous UCB2CTL0 |= UCMST + UCSYNC; //Clock source SMCLK UCB2CTL1 |= UCSSEL_2; // SMCLK //SMCLK/4 = 8Mhz/4 UCB2BR0 = 0x04; // /4 UCB2BR1 = 0; // UCB2CTL1 &= ~UCSWRST; // **Initialize USCI state machine** //Power-On sequence ADS1248AssertCS(0); P9OUT |= ADS1248_START; //Start High P8OUT &= !(ADS1248_RESET); //Reset High __delay_cycles(128000); //0.6ms pause -> oscF*0.6ms=8Mhz*0.6ms = 128000 (as specified in datasheet) ADS1248AssertCS(1); return 0; } /* stop collecting data */ void ADS1248Stop(void) { unsigned char dummy; // Reset SPI ADS1248AssertCS(0); // CS goes high __delay_cycles(30); //Pausa ADS1248AssertCS(1); // CS goes low // Command to stop taking continous readings //Waiting for DRDY low while(P9IN & ADS1248_DRDY); while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = ADS1248_CMD_SDATAC; while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; __delay_cycles(20); Pause ADS1248AssertCS(0); // CS goes high } int ADS1248CargaInicial(void) { int i; int resultado; initSPIads1248(); ADS1248SendResetCommand(); ADS1248Stop(); //We read all the records from AD to store records that are modified //and then we can compare all records ADS1248ReadRegister(); //We copy log records read table to table to write records for(i=0;i<15;i++) regwriteads[i] = regreadads[i]; //We configured the first four records /* MUX0 = 00 Burnout current off 000 AIN0 is positive 001 AIN1 is negative = 0x01 */ regwriteads[ADS1248_MUX0_REGISTER] = 0x01; /* VBIAS = 0x00 No se aplica Vbias */ regwriteads[ADS1248_VBIAS_REGISTER] = 0x00; /* MUX1 = 0 Internal osclilator 01 internal reference always ON (Necesary for IDAC) 00 REF0 external Rbias is used 000 Normal Operation = 0x20 */ regwriteads[ADS1248_MUX1_REGISTER] = 0x20; /*SYS0 = 0 Always is 0 000 Gain is 1 0011 40SPS = 0x03 */ regwriteads[ADS1248_SYS0_REGISTER] = 0x03; //We write the first four registers ADS1248WriteRegister(ADS1248_MUX0_REGISTER , 4); //IDAC0 ad IDAC1 configuration /*IDAC0 = 0000 Always is 0 0 0 DOUT//DRDY pin functions only as Data Out 110 IDAC = 1ma = 0x06*/ regwriteads[ADS1248_IDAC0_REGISTER] = 0x06; /*IDAC1 = 0000 first current source in AIN0 0001 second current source in AIN1 = 0x01*/ regwriteads[ADS1248_IDAC1_REGISTER] = 0x01; //We write the register ADS1248WriteRegister(ADS1248_IDAC0_REGISTER , 2); //We read registers to verify that writing was successful ADS1248ReadRegister(); //we compare registers resultado = 0; for(i=0;i<15;i++) { if (regwriteads[i] != regreadads[i]) resultado = 1; } __delay_cycles(10000); //Pausa return resultado; } /*It writes the control parameters in the registers*/ int ADS1248WriteRegister(int StartAddress, int NumRegs) { int i; unsigned char dummy; unsigned char reg[15]; //Tabla que datos a escribir //Copy data from general table to transmision table for (i=0;i<NumRegs;++i) { reg[i] = regwriteads[StartAddress + i]; } ADS1248Stop(); //Stop collecting data // assert CS to start transfer ADS1248AssertCS(1); // CS goes low //First command: direction of the first writting register while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = ADS1248_CMD_WREG + StartAddress; //second command: number of writting registers while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = NumRegs - 1; //Data bytes: Data of the writting registers while(!(UCB2IFG & UCRXIFG)); dummy=UCB2RXBUF; for (i=0;i<NumRegs;++i) { while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = reg[i]; while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; } __delay_cycles(1000); //Pausa ADS1248AssertCS(0); // CS goes high return 0; } /*It reads the control parameters of the registers*/ void ADS1248ReadRegister() { unsigned char dummy; unsigned char reg[15]; int i=0; ADS1248Stop(); //Stop collecting data __delay_cycles(40); //Pause // Reset SPI ADS1248AssertCS(0); // CS goes high __delay_cycles(10); //Pause ADS1248AssertCS(1); // CS goes low while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = ADS1248_CMD_RREG; // Command for register read while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; while(!(UCB2IFG & UCTXIFG)); UCB2TXBUF = 0x0E; // Command for number of registers to read while(!(UCB2IFG & UCRXIFG)); dummy = UCB2RXBUF; while(i<15) { UCB2TXBUF = 0xff; while(!(UCB2IFG & UCRXIFG)); reg[i] = UCB2RXBUF; // read register data i++; } //Copy read table to general table for(i=0;i<15;i++) regreadads[i] = reg[i]; ADS1248AssertCS(0); // CS goes high }
/* * main.c */ #include "msp430x54x.h" #include "ads1248.h" void init(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT // Initialize LFXT1 P7SEL |= 0x03; // Select XT1 UCSCTL6 &= ~(XT1OFF); // XT1 On UCSCTL6 |= XCAP_3; // Internal load cap C=12.0pF // Loop until XT1 fault flag is cleared do { UCSCTL7 &= ~XT1LFOFFG; // Clear XT1 fault flags }while (UCSCTL7&XT1LFOFFG); // Test XT1 fault flag // Initialize DCO to 2.45MHz __bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx UCSCTL1 = DCORSEL_6; // Set RSELx for DCO = 4.9 MHz UCSCTL2 = FLLD_1 + 243; // Set DCO Multiplier for 2.45MHz // (N + 1) * FLLRef = Fdco // (243 + 1) * 32768 = ___ MHz // Set FLL Div = fDCOCLK/2 __bic_SR_register(SCG0); // Enable the FLL control loop // Worst-case settling time for the DCO when the DCO range bits have been // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization. // 32 x 32 x 8 MHz / 32,768 Hz = 249856 = MCLK cycles for DCO to settle __delay_cycles(249856); } void initRS232(void) { P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 |= UCSWRST; // **Put state machine in reset** UCA0CTL1 |= UCSSEL_2; // CLK = DCO UCA0BR0 = 0x41; // ~8MHz/9600=833 (see User's Guide) UCA0BR1 = 0x03; // //UCA0MCTL = UCBRS_2+UCBRF_0; // Modulation UCBRSx=2, UCBRFx=0 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** //UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt } void enviaRS232(int Code) { while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = Code; } void main(void) { int valor[3]; init(); initRS232(); ADS1248CargaInicial(); while(1) { ADS1248ReadData(valor); enviaRS232(valor[0]); __delay_cycles(20); enviaRS232(valor[1]); __delay_cycles(20); enviaRS232(valor[2]); __delay_cycles(20); } }
The program always stops at the ADS1248Stop functiong, waiting to the DRDY ads1248 pin to goes low (the line says: while(P9IN & ADS1248_DRDY);)
I don't know if it is a programming error or a hardware error. I've connected this pins between the ADS and the MSP:
ADS pin 1: 5V
ADS pin 2: gnd
ADS pin 3: gnd
ADS pin 4: MPS pin 67
ADS pin 11 and 12: function generator with sinusoidal waveform
ADS pin 23: MPS pin 74
ADS pin 24: MPS pin 68
ADS pin 25: MPS pin 75
ADS pin 26: MPS pin 70
ADS pin 27: MPS pin 69
ADS pin 28: MPS pin 71
The other pins aren't connected.
Thanks in advance