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

MSP432P401R透過SPI接收連續數據

MSP432P401R為master,接收連續數據時,是否需要連續傳送0x00虛擬位元,才有辦法接收slave傳送過來的資料?

Susan Yang:

连续接收时是不需要連續傳送0x00虛擬位元的

user5121970:

回复 Susan Yang:

可是如果沒有連續傳送0X00的話,我發現無法接收slave所傳送的資料。

我是用ads1299作為slave傳送data給MSP432P401R,代碼如下

結果在邏輯分析儀上有SPI的MISO有數據,但最後的B陣列裡面的數值不是正確的。

我不清楚SPI接收連續數據的寫法是否有誤?

#include <ti/devices/msp432p4xx/driverlib/driverlib.h>/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
#define HZ3000000UL
/* 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 ) ;
}

linzhuang jia:

回复 user5121970:

连续接收时是需要连续发送的,SPI是环状的,也就是说,master需要不断发送字节才能接收slave的数据。
看了你的程序,直接使用了底层的 DriverLib开发,这需要对寄存器很熟悉,而且程序显得非常复杂,开发效率很低。建议你在 simplelink_msp432p4_sdk 上开发程序,调用 TI-DRIVER 层的 API,程序会大幅度简化。 simplelink_msp432p4_sdk安装之后,里面有关于 SPI 的例子程序

gaoyang9992006:

回复 linzhuang jia:

多谢分享。

赞(0)
未经允许不得转载:TI中文支持网 » MSP432P401R透過SPI接收連續數據
分享到: 更多 (0)