工具/软件:Code Composer Studio
大家好、
我正在使用 TM4C123GH6PM 开发。 我已将一个板配置为主板、将另一个板配置为从板。 我正在尝试从主设备向从设备发送数据。 但从器件中未正确接收到数据。
此致、
Siva
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
大家好、
我正在使用 TM4C123GH6PM 开发。 我已将一个板配置为主板、将另一个板配置为从板。 我正在尝试从主设备向从设备发送数据。 但从器件中未正确接收到数据。
此致、
Siva
这是我的主代码
//spi_master.c
/**
* main.c
*
#include
#include
#include
#include
#include "tm4c123gh6pm .h"
void uart0_init ()//UART 0
{
SYSCTL_RCGCUART_R |=0x00000001;
SYSCTL_RCGCGPIO_R |=0x00000001;
GPIO_PORta_lock_R |=0x4C4F434B;
GPIO_PORta_CR_R |=0x00000003;
GPIO_Porta_DEN_R |=0x00000003;
GPIO_PORta_AFSEL_R |=0x00000003;
GPIO_Porta_PCTL_R |=0x00000011;
UART0_CTL_R &=~0x00000001;
UART0_IBRD_R =104;
UART0_FBRD_R=11;
UART0_LCRH_R |=0x00000060;
UART0_CC_R |=0x00000000;
UART0_CTL_R |=0x00000301;
}
void U0_send (无符号字符*p)
{
while (* p)
{
while (((UART0_FR_R 和0x20)!= 0);
UART0_DR_R=*p++;
}
}
空延迟(unsigned int x)
{
unsigned int i、j;
for (i=0;<x;i++))
{
对于(j=0;<x;j++)
{
}
}
}
void SPI_init()
{
//时钟配置
SYSCTL_RCGCSSI_R |=0x00000001;
SYSCTL_RCGCGPIO_R|=0x00000001;
// GPIO 配置
GPIO_Porta_AFSEL_R|=0x0000003C;
GPIO_Porta_PCTL_R |=0x00222200;
GPIO_Porta_DEN_R |=0x0000003C;
GPIO_PORta_PUR_R |=0x0000003C;
GPIO_Porta_DR8R_R |=0x0000003C;
/SSI 配置
SSI0_CR1_R &=~0x00000002;//1.
SSI0_CR1_R |=0x00000000;//2.
SSI0_CC_R |=0x00000000;//3.
SSI0_CPSR_R |=0x00000002;//4。
SSI0_CR0_R |=0x000007C7;//5.
SSI0_CR1_R |=0x00000002;//6.
}
空缓冲区(无符号字符 k)
{
while ((SSI0_SR_R &0x00000001)=0);//Tx FIF0不为空
SSI0_DR_R =k;
}
void send_Byte (unsigned char * ptr)
{
while (* ptr)
{
Buffer(*PTR++);
}
}
int main()
{
uart0_init();
延迟(2000年);
U0_SEND ("UART master initialized\r\n");
spi_init();
while (1)
{
SEND_BYTE ("k");
延迟(1000);
U0_SEND ("sucess\r\n");
}
}
//这是我的从代码
/**
* main.c
*
#include
#include
#include
#include
#include "tm4c123gh6pm .h"
unsigned char d;
void SPI_init()
{
//时钟配置
SYSCTL_RCGCSSI_R |=0x00000001;
SYSCTL_RCGCGPIO_R|=0x00000001;
// GPIO 配置
GPIO_Porta_AFSEL_R|=0x0000003C;
GPIO_Porta_PCTL_R |=0x00222200;
GPIO_Porta_DEN_R |=0x0000003C;
GPIO_PORta_PUR_R |=0x0000003C;
GPIO_Porta_DR8R_R |=0x0000003C;
/SSI 配置
SSI0_CR1_R &=~0x00000002;//1.
SSI0_CR1_R |=0x00000000;//2.
SSI0_CC_R |=0x00000000;//3.
SSI0_CPSR_R |=0x00000002;//4。
SSI0_CR0_R |=0x000007C7;//5.
SSI0_CR1_R |=0x00000006;//6。
}
void uart0_init ()//UART 0
{
SYSCTL_RCGCUART_R |=0x00000001;
SYSCTL_RCGCGPIO_R |=0x00000001;
GPIO_PORta_lock_R |=0x4C4F434B;
GPIO_PORta_CR_R |=0x00000003;
GPIO_Porta_DEN_R |=0x00000003;
GPIO_PORta_AFSEL_R |=0x00000003;
GPIO_Porta_PCTL_R |=0x00000011;
UART0_CTL_R &=~0x00000001;
UART0_IBRD_R =104;
UART0_FBRD_R=11;
UART0_LCRH_R |=0x00000060;
UART0_CC_R |=0x00000000;
UART0_CTL_R |=0x00000301;
}
char SPI_recv()
{
while (((SSI0_SR_R & 0x00000004)==0);// Rx 不为空
返回 SSI0_DR_R;
}
void U0_send (无符号字符*p)
{
while (* p)
{
while (((UART0_FR_R 和0x20)!= 0);
UART0_DR_R=*p++;
}
}
空延迟(unsigned int x)
{
unsigned int i、j;
for (i=0;<x;i++))
{
对于(j=0;<x;j++)
{
}
}
}
int main (空)
{
spi_init();
延迟(1000);
uart0_init();
延迟(1000);
U0_SEND ("UART slave new initialized\r\n");
while (1)
{
d=SPI_recv();
延迟(1000);
U0_SEND (d);
延迟(1000);
}
}
您好!
请参阅以下主题中的#4。
e2e.ti.com/.../695568
我建议您使用示波器来捕获 SPI 波形、以确定问题是主器件还是从器件。 主器件需要在从器件使用 MISO 发送其数据时生成 SPI 时钟和 MOSI 信号。 如果您在 SPICLK 和 MOSI 上看到正确的信号、则主器件可能正常。 您可以将隔离调试发送到从器件。 确保您的从器件具有匹配的波特率、时钟极性和相位、以便正常工作。 检查 DR 寄存器和状态寄存器、查看它们是否正在接收任何数据并设置任何标志。