我利用MSP432P401R与ADS1299进行沟通,我利用SPI读取ADS1299连续数据,MSP432P401R为master,ADS1299为slave,在此之前我已成功利用MSP432P401R写入和读取暂存器,并且都成功,但是读取连续数据却有很大的问题。
以下为我目前遇到的几个问题整理:
1.如果要读取测试方波,并且我只需要使用一个通道,请问我的所有暂存器之值是否设定正确,通道1为内部测试讯号方波,其余通道均无讯号。
2.读取连续数据时,master是否需要连续传送虚拟位元0x00至slave。
3.读去连续数据时,每一个DRDY之间都会输出一个stat+8个通道值,因为我只使用到1个通道,我要如何让通道1的值和其余通道分开。
4.我测试过让通道1与其他通道值皆为0x61 Input shorted (for offset or noise measurements),但结果显示我的SPI好像没有作用,无法接收到连续传输的数据,理论上应该所有数值皆为0,但结果却有数值。
以下为我目前的程式码
#include /* Standard Includes */#include #include #define HZ 3000000UL/* Sta
tics */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, // *** = 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 ) ;}