TI中文支持网
TI专业的中文技术问题咨询交流网站

ads1299讀取連續數據

我利用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 <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 Source3000000,// SMCLK = DCO = 3MHZ500000,// *** = 500khzEUSCI_B_SPI_MSB_FIRST,// MSB FirstEUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT,// PhaseEUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // LOW polarityEUSCI_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();//初始化ADS1299P3->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//CONFIG3while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));SPI_transmitData(EUSCI_B0_BASE, 0x43);  //CONFIG3while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));SPI_transmitData(EUSCI_B0_BASE, 0x00);  //CONFIG3while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));SPI_transmitData(EUSCI_B0_BASE, 0xE0);  //CONFIG3//CONFIG1while (!(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//CONFIG2while (!(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);//Channel1while (!(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);//Channel2while (!(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);//Channel3while (!(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);//Channel4while (!(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);//Channel5while (!(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);//Channel6while (!(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);//Channel7while (!(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);//Channel8while (!(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 Highwhile (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));SPI_transmitData(EUSCI_B0_BASE, 0x10);  //RDATACfor(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); //傳送虛擬位元0x00A = 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 ) ;
}

mangui zhang:

最好抓取一下SPI波形与手册中的波形对比一下

赞(0)
未经允许不得转载:TI中文支持网 » ads1299讀取連續數據
分享到: 更多 (0)