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.

TM4C123GH6PM: SPI receiver error

Part Number: TM4C123GH6PM

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 */
}

  • Hi,

      First of all, you are writing in a DRM (Direct Memory Manipulation) style of coding which we don't support. We provide TivaWare library which contains peripheral drivers that will easily setup the peripherals for you. 

     With that said I can provide some troubleshooting tips on SPI communication. I'm assuming your problem is that the slave is receiving 0. Is that a correct understanding?

      First, please use a scope to capture the bus traffic. Do you see your master sending out the correct data? If the master is sending out data correctly and the slave is receiving 0 then the problem is on the slave side. If the master is sending out 0 then it is obvious the slave will receive 0. So first thing first, check on the scope what is sent out by the master.

     On your slave side's code you have inconsistent comments. See below. Therefore, I will ask you to double check if you are configuring the slave SPI properly. At first, you said you are configuring for SPI master with 4MHz and 16-bit data and later you have comment that says 8MHz and 8-bit. Both the master and slave must have matching speed, phase, polarity and character length in order to communicate. You must make sure that one is master and the other is a slave, not both are masters. 

    /* 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 */