TI中文支持网
TI专业的中文技术问题搜集分享网站

28379D SPI master 发送数据

最近在使用28379D作为SPI 主机与从机芯片通信时遇到一些问题,请大家赐教。

我将SPIA作为master通信,从机是一个集成了ADF4158芯片的模块,只需要基于SCK,MOSI与片选CS即可。因此在硬件设计上,我只将GPIO16(SPISIMOA)、GPIO18(***)分别与该模块的SIMO和CLK相连,另用一个GPIO作为从机的片选信号。

我目前存在的疑惑有:

(1)GPIO17和GPIO19都悬空,不知这样是否会影响SPI的正常工作?

(2)我没有采用FIFO模式,不知这个模式与普通SPI有何区别?

(3)在我只需要主机发送数据,而不需要读取从机返回的数据时,以下代码是否能够成功实现8bit数据TxData的传输?

uint8_t REF_SPI_ReadWriteByte(uint8_t TxData)
{uint8_t dummy = 0;// waiting for the complement of  previous character shiftingwhile(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) { }SpiaRegs.***.bit.TALK = 1; // Enable Transmit pathSpiaRegs.SPITXBUF = TxData; // Master transmits datawhile(SpiaRegs.SPISTS.bit.INT_FLAG !=1){}//Non-FIFO modedummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself bc it rx’d same data tx’dreturn dummy;

}

(4)实际的需求是需要向从机写32bit的指令,一共有七条指令需要写入,以下代码能否实现我想要的功能?(temp即为需要同一次写入的32bit指令,从机芯片要求在写入前将片选RADAR_SPI_TX_CS拉低,写完后再拉高)

static void WriteToADF4158(uint32_t* buff,uint32_t address)
{uint32_t temp;temp = *(buff + address);GPIO_WritePin(RADAR_SPI_TX_CS,0);//enableDelay_ms(20);REF_SPI_ReadWriteByte((uint8_t)(temp>>24));REF_SPI_ReadWriteByte((uint8_t)(temp>>16));REF_SPI_ReadWriteByte((uint8_t)(temp>>8));REF_SPI_ReadWriteByte((uint8_t)(temp));Delay_ms(40);GPIO_WritePin(RADAR_SPI_TX_CS,1);//disable

}

(5)在这些代码的配置下,从机的输出看起来就是噪声,感觉根本没有数据写入。由于DSP选用的是ZWT封装,SPI接口模块也无法用探针去测试SCK或者MOSI的波形,我该如何验证呢?

以下是我相关SPI的配置代码,其中SPI的速率设置为500kHz,满足从机的时钟需求:

void InitSpiaGpio()
{EALLOW;//// Enable internal pull-up for the selected pins//// Pull-ups can be enabled or disabled by the user.// This will enable the pullups for the specified pins.// Comment out other unwanted lines.//GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;  // Enable pull-up on GPIO16 (SPISIMOA)
//  GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0;// Enable pull-up on GPIO5 (SPISIMOA)GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;  // Enable pull-up on GPIO17 (SPISOMIA)
//  GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;// Enable pull-up on GPIO3 (SPISOMIA)GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0;  // Enable pull-up on GPIO18 (***)
//GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;  // Enable pull-up on GPIO19 (SPISTEA)//// Set qualification for selected pins to asynch only//// This will select asynch (no qualification) for the selected pins.// Comment out other unwanted lines.//GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
//  GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 3;  // Asynch input GPIO5 (SPISIMOA)GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
//  GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3;  // Asynch input GPIO3 (SPISOMIA)GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (***)
//GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)////Configure SPI-A pins using GPIO regs//// This specifies which of the possible GPIO pins will be SPI functional// pins.// Comment out other unwanted lines.//GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
//  GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 2;  // Configure GPIO5 as SPISIMOAGpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
//  GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2;  // Configure GPIO3 as SPISOMIAGpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as ***
//GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEAEDIS;
}
void InitSpia(void)
{// Initialize SPI-A// Set reset low before configuration changes// Clock polarity (0 == rising, 1 == falling)// 16-bit character// Enable loop-backSpiaRegs.***.bit.SPISWRESET = 0;SpiaRegs.***.bit.CLKPOLARITY = 0;SpiaRegs.***.bit.*** = (8-1);//(16-1)SpiaRegs.***.bit.SPILBK = 0;//1;loopback disable(0)// Enable master (0 == slave, 1 == master)// Enable transmission (Talk)// Clock phase (0 == normal, 1 == delayed)// SPI interrupts are disabledSpiaRegs.***.bit.MASTER_SLAVE = 1;SpiaRegs.***.bit.TALK = 1;SpiaRegs.***.bit.CLK_PHASE = 0;//0SpiaRegs.***.bit.SPIINTENA = 0;// Set the baud rateSpiaRegs.SPIBRR.bit.SPI_BIT_RATE = SPI1_BRR;// Set FREE bit// Halting on a breakpoint will not halt the SPISpiaRegs.SPIPRI.bit.FREE = 1;SpiaRegs.SPIPRI.bit.TRIWIRE = 0;
SpiaRegs.SPIFFTX.bit.SPIFFENA = 0;//disable FIFO// Release the SPI from resetSpiaRegs.***.bit.SPISWRESET = 1; }


希望大家能帮帮我,每个问题可能都很琐碎,错误也可能很基础,谢谢大家的不吝赐教!

mangui zhang:1.如果确定外接芯片端是slave,只需要三根信号线就可以;
2.不用FIFO,和普通SPI接口无区别;
3.问题是你的CS是MCU SPI时序自动产生的还是用其他GPIO,应该也是有寄存器配置的,目前建议你一直发送数据,用示波器
抓时钟和数据的波形、抓CS和数据的波形等对比分析;
4.只要CS控制合理肯定是可以实现多个字节写出的;

最近在使用28379D作为SPI 主机与从机芯片通信时遇到一些问题,请大家赐教。

我将SPIA作为master通信,从机是一个集成了ADF4158芯片的模块,只需要基于SCK,MOSI与片选CS即可。因此在硬件设计上,我只将GPIO16(SPISIMOA)、GPIO18(***)分别与该模块的SIMO和CLK相连,另用一个GPIO作为从机的片选信号。

我目前存在的疑惑有:

(1)GPIO17和GPIO19都悬空,不知这样是否会影响SPI的正常工作?

(2)我没有采用FIFO模式,不知这个模式与普通SPI有何区别?

(3)在我只需要主机发送数据,而不需要读取从机返回的数据时,以下代码是否能够成功实现8bit数据TxData的传输?

uint8_t REF_SPI_ReadWriteByte(uint8_t TxData)
{uint8_t dummy = 0;// waiting for the complement of  previous character shiftingwhile(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) { }SpiaRegs.***.bit.TALK = 1; // Enable Transmit pathSpiaRegs.SPITXBUF = TxData; // Master transmits datawhile(SpiaRegs.SPISTS.bit.INT_FLAG !=1){}//Non-FIFO modedummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself bc it rx’d same data tx’dreturn dummy;

}

(4)实际的需求是需要向从机写32bit的指令,一共有七条指令需要写入,以下代码能否实现我想要的功能?(temp即为需要同一次写入的32bit指令,从机芯片要求在写入前将片选RADAR_SPI_TX_CS拉低,写完后再拉高)

static void WriteToADF4158(uint32_t* buff,uint32_t address)
{uint32_t temp;temp = *(buff + address);GPIO_WritePin(RADAR_SPI_TX_CS,0);//enableDelay_ms(20);REF_SPI_ReadWriteByte((uint8_t)(temp>>24));REF_SPI_ReadWriteByte((uint8_t)(temp>>16));REF_SPI_ReadWriteByte((uint8_t)(temp>>8));REF_SPI_ReadWriteByte((uint8_t)(temp));Delay_ms(40);GPIO_WritePin(RADAR_SPI_TX_CS,1);//disable

}

(5)在这些代码的配置下,从机的输出看起来就是噪声,感觉根本没有数据写入。由于DSP选用的是ZWT封装,SPI接口模块也无法用探针去测试SCK或者MOSI的波形,我该如何验证呢?

以下是我相关SPI的配置代码,其中SPI的速率设置为500kHz,满足从机的时钟需求:

void InitSpiaGpio()
{EALLOW;//// Enable internal pull-up for the selected pins//// Pull-ups can be enabled or disabled by the user.// This will enable the pullups for the specified pins.// Comment out other unwanted lines.//GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;  // Enable pull-up on GPIO16 (SPISIMOA)
//  GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0;// Enable pull-up on GPIO5 (SPISIMOA)GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;  // Enable pull-up on GPIO17 (SPISOMIA)
//  GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0;// Enable pull-up on GPIO3 (SPISOMIA)GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0;  // Enable pull-up on GPIO18 (***)
//GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0;  // Enable pull-up on GPIO19 (SPISTEA)//// Set qualification for selected pins to asynch only//// This will select asynch (no qualification) for the selected pins.// Comment out other unwanted lines.//GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
//  GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 3;  // Asynch input GPIO5 (SPISIMOA)GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
//  GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3;  // Asynch input GPIO3 (SPISOMIA)GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (***)
//GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)////Configure SPI-A pins using GPIO regs//// This specifies which of the possible GPIO pins will be SPI functional// pins.// Comment out other unwanted lines.//GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
//  GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 2;  // Configure GPIO5 as SPISIMOAGpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
//  GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2;  // Configure GPIO3 as SPISOMIAGpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as ***
//GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEAEDIS;
}
void InitSpia(void)
{// Initialize SPI-A// Set reset low before configuration changes// Clock polarity (0 == rising, 1 == falling)// 16-bit character// Enable loop-backSpiaRegs.***.bit.SPISWRESET = 0;SpiaRegs.***.bit.CLKPOLARITY = 0;SpiaRegs.***.bit.*** = (8-1);//(16-1)SpiaRegs.***.bit.SPILBK = 0;//1;loopback disable(0)// Enable master (0 == slave, 1 == master)// Enable transmission (Talk)// Clock phase (0 == normal, 1 == delayed)// SPI interrupts are disabledSpiaRegs.***.bit.MASTER_SLAVE = 1;SpiaRegs.***.bit.TALK = 1;SpiaRegs.***.bit.CLK_PHASE = 0;//0SpiaRegs.***.bit.SPIINTENA = 0;// Set the baud rateSpiaRegs.SPIBRR.bit.SPI_BIT_RATE = SPI1_BRR;// Set FREE bit// Halting on a breakpoint will not halt the SPISpiaRegs.SPIPRI.bit.FREE = 1;SpiaRegs.SPIPRI.bit.TRIWIRE = 0;
SpiaRegs.SPIFFTX.bit.SPIFFENA = 0;//disable FIFO// Release the SPI from resetSpiaRegs.***.bit.SPISWRESET = 1; }


希望大家能帮帮我,每个问题可能都很琐碎,错误也可能很基础,谢谢大家的不吝赐教!

Susan Yang:

liky Zhao

(1)GPIO17和GPIO19都悬空,不知这样是否会影响SPI的正常工作?

不会,但您需要注意悬空时的配置

http://www.ti.com/lit/ds/symlink/tms320f28379d.pdf 的 Table 4-7. Connections for Unused Pins

liky Zhao

(2)我没有采用FIFO模式,不知这个模式与普通SPI有何区别?

若是不用FIFO模式,与普通SPI是一样的

liky Zhao

(3)在我只需要主机发送数据,而不需要读取从机返回的数据时,以下代码是否能够成功实现8bit数据TxData的传输?

内部 SPI 通信数据寄存器是 16bit 的,而且发送的数据是左对齐的。所以,当 spi 通信不是 16bit 时,应向将待发送的数据左移到 MSB,再发送相应位数。

建议您参考
C2000Ware下的例程 C:\ti\c2000\C2000Ware_2_00_00_02\driverlib\f2837xd\examples\cpu1\spi

赞(0)
未经允许不得转载:TI中文支持网 » 28379D SPI master 发送数据
分享到: 更多 (0)