Other Parts Discussed in Thread: ADS1299
Tool/software: Code Composer Studio
I use MSP432P401R to communicate with ADS1299, I use SPI to read ADS1299 continuous data, MSP432P401R is master, ADS1299 is slave, before that I have successfully used MSP432P401R to write and read the scratchpad, and both were successful, but the reading was continuous There are big problems with the data.
The following is a summary of the problems I have encountered currently:
1. If you want to read the test square wave, and I only need to use one channel, may I ask if all the values of my registers are set correctly, channel 1 is the internal test signal square wave, and the other channels have no signal.
2. When reading continuous data, does the master need to continuously transmit virtual bits 0x00 to slave.
3. When reading continuous data, a stat + 8 channel value will be output between each DRDY, because I only use 1 channel, how do I make the value of channel 1 separate from the other channels.
4. I have tested that the values of channel 1 and other channels are 0x61Input shorted (for offset or noise measurements) x61Input shorted (for offset or noise measurements), but the results show that my SPI seems to be ineffective and cannot receive continuously transmitted data In theory, all values should be 0, but the results have values.
The following is my current code
#include <ti/devices/msp432p4xx/driverlib/driverlib.h> /* Standard Includes */ #include <stdint.h> #include <stdbool.h> #define HZ 3000000UL /* Statics */ static volatile uint8_t RXData = 0; static uint8_t TXData = 0; int i = 0; int a = 0; int z = 0; int j = 0; //#define A[500]; uint8_t A; uint32_t B[1000]; //uint8_t A[500]; uint8_t hibyte,midbyte,lowbyte; uint32_t intQA; //![Simple SPI Config] /* SPI Master Configuration Parameter */ const eUSCI_SPI_MasterConfig spiMasterConfig = { EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source 3000000, // SMCLK = DCO = 3MHZ 500000, // SPICLK = 500khz EUSCI_B_SPI_MSB_FIRST, // MSB First EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, // Phase EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // LOW polarity EUSCI_B_SPI_3PIN // 3Wire SPI Mode }; //![Simple SPI Config] int main(void) { /* Halting WDT */ WDT_A_holdTimer(); //![Simple SPI Example] /* Selecting P1.5 P1.6 and P1.7 in SPI mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* Configuring SPI in 3wire master mode */ SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig); /* Enable SPI module */ SPI_enableModule(EUSCI_B0_BASE); /* Enabling interrupts */ //SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT); //Interrupt_enableInterrupt(INT_EUSCIB0); //Interrupt_enableSleepOnIsrExit(); //初始化ADS1299 P3->DIR |= BIT0; P3->OUT ^= BIT0; //CS_Low __delay_cycles(HZ); P3->DIR |= BIT5; P3->OUT = BIT5; //CLKSEL High __delay_cycles(HZ/1000); P5->DIR |= BIT1; P5->OUT = BIT1; //PWDN High __delay_cycles(HZ); P2->DIR |= BIT7; P2->OUT = BIT7; //RESET High __delay_cycles(HZ); P2->DIR |= BIT7; P2->OUT ^= BIT7; //RESET LOW __delay_cycles(HZ); P2->DIR |= BIT7; P2->OUT = BIT7; //RESET High __delay_cycles(HZ); /////////////////////////////////////////////////// while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x11); //SDATAC //CONFIG3 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x43); //CONFIG3 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); //CONFIG3 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0xE0); //CONFIG3 //CONFIG1 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x41); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x96);//採樣率250 //CONFIG2 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x42); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0xD0); //Channel1 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x45); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x65); //SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel2 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x46); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel3 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x47); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel4 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x48); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel5 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x49); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel6 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x4A); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel7 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x4B); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); //Channel8 while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x4C); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x00); while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x61); P2->DIR |= BIT6; P2->OUT |= BIT6; //Set Start High while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); SPI_transmitData(EUSCI_B0_BASE, 0x10); //RDATAC for(i;i<1000;i++) { int32_t outputcode = adc_read_data(); B[a] = outputcode; a++; } //PCM_gotoLPM0(); //__no_operation(); } uint8_t read_continue_data(){ SPI_transmitData(EUSCI_B0_BASE, 0x00); //傳送虛擬位元0x00 A = SPI_receiveData(EUSCI_B0_BASE); //將接收到的資料存進A陣列 //return read_continue_data; // return 0; } uint32_t adc_read_data(void) { uint8_t adcCode[3]; adcCode[0] = read_continue_data(); adcCode[1] = read_continue_data(); adcCode[2] = read_continue_data(); return ((int32_t)(((adcCode[0] & 0x80) ? (0x00) : (0xFF)) ) << 24) | ((adcCode[0] & 0xFF) << 16) | ((adcCode[1] & 0xFF) << 8 ) | ((adcCode[2] & 0xFF) << 0 ) ; }