dsp28335 + w5500网络模块通过spi通信配置不同求大神帮忙有代码
时间:10-02
整理:3721RD
点击:
Spi配置:
SpiaRegs.SPICCR.bit.SPISWRESET = 0;//软件复位SPI
SpiaRegs.SPICCR.all = 0x07;//数据长度为8bit、0x0007禁止内部回路模式模式0x0017开启
SpiaRegs.SPICTL.all = 0x06;/使能Master/Slave XMIT
SpiaRegs.SPISTS.all = 0x0000;//状态寄存器
SpiaRegs.SPIBRR = 0x05;//设置波特率
InitSpiGpio();//从初始化功能引脚
SpiaRegs.SPICCR.bit.SPISWRESET = 1;//重新使能SPI
InitSpiGpio();//从初始化功能引脚
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up on GPIO18 (SPICLKA)
GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up on GPIO19 (SPISTEA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 0; // Configure GPIO19 as SPISTEA
EDIS;
通过spi发送接收数据
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=0);
SpiaRegs.SPITXBUF = (byte<<8);//发送信息
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=0);
while(SpiaRegs.SPISTS.bit.INT_FLAG!=0)
recvData = SpiaRegs.SPIRXBUF&0x00FF;
SpiaRegs.SPICCR.bit.SPISWRESET = 0;//软件复位SPI
SpiaRegs.SPICCR.all = 0x07;//数据长度为8bit、0x0007禁止内部回路模式模式0x0017开启
SpiaRegs.SPICTL.all = 0x06;/使能Master/Slave XMIT
SpiaRegs.SPISTS.all = 0x0000;//状态寄存器
SpiaRegs.SPIBRR = 0x05;//设置波特率
InitSpiGpio();//从初始化功能引脚
SpiaRegs.SPICCR.bit.SPISWRESET = 1;//重新使能SPI
InitSpiGpio();//从初始化功能引脚
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up on GPIO18 (SPICLKA)
GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up on GPIO19 (SPISTEA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 0; // Configure GPIO19 as SPISTEA
EDIS;
通过spi发送接收数据
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=0);
SpiaRegs.SPITXBUF = (byte<<8);//发送信息
while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=0);
while(SpiaRegs.SPISTS.bit.INT_FLAG!=0)
recvData = SpiaRegs.SPIRXBUF&0x00FF;
你的问题解决了吗?我也在弄这个,买了一个W5500串口转以太网的模块,调不好,能交流下吗?