Hello,
i have a problem with the data that received in my project for spi
when i change data that transmit from master receiver still receiving zero's
their is the master code
#include "TM4C123GH6PM.h"
void init_SSI1(void);
void SSI1Write(unsigned char data);
unsigned char SSI1Read(void);
unsigned char Send_Char[1024];
unsigned char Receive_Char[1024];
long Num=0;
int main(void)
{
init_SSI1();
while(1)
{
SSI1Write(Send_Char[Num]); /* write a character */
Num++;
if(Num==1024)
Num=0;
}
}
unsigned char SSI1Read(void)
{
while((SSI1_SR_R & 3) != 3); /* wait until FIFO full */
return SSI1_DR_R; /* return receiving data */
}
void SSI1Write(unsigned char data)
{
GPIO_PORTF_DATA_R &= ~0x04; /* assert SS low */
while((SSI1_SR_R & 1) != 1); /* wait until FIFO not full */
SSI1_DR_R = data; /* transmit high byte */
while(SSI1_SR_R & 0x10); /* wait until transmit complete */
GPIO_PORTF_DATA_R |= 0x04; /* keep SS idle high */
}
void init_SSI1(void)
{
SYSCTL_RCGCSSI_R |= SYSCTL_RCGCSSI_R1; /* enable clock to SSI1 */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R3; /* enable clock to GPIOD for SSI1 */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5; /* enable clock to GPIOF for slave select */
/* configure PORTD 3, 1 for SSI1 clock and Tx */
GPIO_PORTD_AMSEL_R &= ~0x09; /* disable analog for these pins */
GPIO_PORTD_DEN_R |= 0x09; /* and make them digital */
GPIO_PORTD_AFSEL_R |= 0x09; /* enable alternate function */
GPIO_PORTD_PCTL_R &= ~0x0000F00F; /* assign pins to SSI1 */
GPIO_PORTD_PCTL_R |= 0x00002002; /* assign pins to SSI1 */
/* configure PORTF 2 for slave select */
GPIO_PORTF_DEN_R |= 0x04; /* make the pin digital */
GPIO_PORTF_DIR_R |= 0x04; /* make the pin output */
GPIO_PORTF_DATA_R |= 0x04; /* keep SS idle high */
/* SPI Master, POL = 0, PHA = 0, clock = 4 MHz, 16 bit data */
SSI1_CR1_R = 0; /* disable SSI and make it master */
SSI1_CC_R = 0; /* use system clock */
SSI1_CPSR_R = 2; /* prescaler divided by 2 */
SSI1_CR0_R = 0x0007; /* 8 MHz SSI clock, SPI mode, 8 bit data */
SSI1_CR1_R |= 2; /* enable SSI1 */
}
and this the receiver code
#include "TM4C123GH6PM.h"
void init_SSI1(void);
unsigned char SSI1Read(void);
unsigned char data;
unsigned char Receive_Char[1024];
long Num=0;
int main(void)
{
init_SSI1();
while(1)
{
Receive_Char[Num]=SSI1Read(); /* write a character */
Num++;
if(Num==1024)
Num=0;
}
}
unsigned char SSI1Read(void)
{
while((SSI1_SR_R & 2) != 2); /* wait until FIFO full */
return SSI1_DR_R; /* return receiving data */
}
void init_SSI1(void)
{
SYSCTL_RCGCSSI_R |= SYSCTL_RCGCSSI_R1; /* enable clock to SSI1 */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R3; /* enable clock to GPIOD for SSI1 */
SYSCTL_RCGCGPIO_R |= SYSCTL_RCGCGPIO_R5; /* enable clock to GPIOF for slave select */
/* configure PORTD 2, 1 for SSI1 clock and Tx */
GPIO_PORTD_AMSEL_R &= ~0x05; /* disable analog for these pins */
GPIO_PORTD_DEN_R |= 0x05; /* and make them digital */
GPIO_PORTD_AFSEL_R |= 0x05; /* enable alternate function */
GPIO_PORTD_PCTL_R &= ~0x00000F0F; /* assign pins to SSI1 */
GPIO_PORTD_PCTL_R |= 0x00000202; /* assign pins to SSI1 */
/* configure PORTF 2 for slave select */
GPIO_PORTF_DEN_R |= 0x04; /* make the pin digital */
GPIO_PORTF_DIR_R |= 0x04; /* make the pin output */
GPIO_PORTF_DATA_R |= 0x04; /* keep SS idle high */
/* SPI Master, POL = 0, PHA = 0, clock = 4 MHz, 16 bit data */
SSI1_CR1_R = 4; /* disable SSI and make it slave */
SSI1_CC_R = 0; /* use system clock */
SSI1_CPSR_R = 2; /* prescaler divided by 2 */
SSI1_CR0_R = 0x0007; /* 8 MHz SSI clock, SPI mode, 8 bit data */
SSI1_CR1_R |= 2; /* enable SSI1 */
}