#include "tm4c123xx.h"
#include <stdint.h>
unsigned char dta;
void init_config(void)
{
//CLOCK CONFIG
SYSCTL_RCGCUART_R |= (1 << 0); //UART0 PORT CLOCK
SYSCTL_RCGCSSI_R |= (1 << 0); //CLOCK FOR SPI MODULE 0
SYSCTL_RCGCGPIO_R |= (1 << 0); //CLOCK FOR PORTA
//UART0 CONFIG
UART0_CTL_R &= (~(1 << 0)) & (~(1 << 8)) & (~(1 << 9)); //UART0 DISABLING BEFORE CONFIG
UART0_IBRD_R = 104; //BAUD RATE INTERGER PART
UART0_FBRD_R = 11; //BAUD RATE FRACTIONAL PART
UART0_LCRH_R |= (0x3 << 5); //WORD LENGTH - 8 BITS
UART0_CC_R = 0x05; //SELECTING POSC
UART0_CTL_R |= (1 << 0) | (1 << 8) | (1 << 9); //0-UART ENABLE,8-TRANSMIT ENABLE,9-RECEIVE ENABLE
//CONFIG PA0,PA1
GPIO_PORTA_AFSEL_R |= (1 << 0) | (1 << 1); //TO SELECT ALTERNATE FUNCTIONS
GPIO_PORTA_PCTL_R |= (1 << 0) | (1 << 4); //SELECTING UART FUNCTION
GPIO_PORTA_DEN_R |= (1 << 0) | (1 << 1); //DIGITIALIZING PA0,PA1
//PA2,PA3,PA4,PA5 CONFIG
GPIO_PORTA_AFSEL_R |= (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5);
GPIO_PORTA_PCTL_R |= 0x00222200;
GPIO_PORTA_DEN_R |= (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5);
//SSI0 CONFIG ==CPOL=1,CPOL=1
SSI0_CR1_R &= (~(1 << 1));
SSI0_CR1_R |= (1 << 2); // slave mode
SSI0_CC_R = 0x0; // SELECTING SYSTEM CLOCK
SSI0_CPSR_R = 128; // DATASHEET - 1MBPS
SSI0_CR0_R = 0xC7; // SELECT DATA SIZE AS 8BIT AND FRAME AS FREE SCALE FRAME AND SPO AND SPH AS 0 AND SCR AS 0
SSI0_CR1_R |= (1 << 1); // ENABLE THE Spi module
}
void spi_receive(void)
{
while (((SSI0_SR_R >> 3) & 0x1) == 0);
dta = SSI0_DR_R;
}
void my_Int_config(void)
{
NVIC_EN0_R = (1<<7); //spi0 interrupt
NVIC_PRI1_R = (3<<28); //highest priority
SSI0_IM_R = (1<<2); //spi0 rx interrupt
}
void IntDefaultHandler(void) //this function in startup code
{
if((SSI0_MIS_R>>2)&1)
dta = spi_receive();
//interrupt need not be cleared as it is autocleared
}
int main()
{
init_config();
my_Int_config();
while (1)
{
/* Displaying in UART */
while ((UART0_FR_R & (1 << 5)) != 0);
UART0_DR_R = dta;
}
}
the above code is board to board communication from an SPI Master(TM4c123 configured as master) to an SPI slave(TM4C123 configured as slave). I am continuously send 'a' from the master side. I checked the output using Logic Analyzer. From slave side, the information I should get in MISO(slave RX pin), I am getting it from MOSI(slave Tx pin). Quite confused of what I should do. Master is sending 'a'. Why is slave sending it back.? The MISO line is always high in both slave and master and same output in both slave and master. Without interrupt method, I am getting garbage data along with the information I sent and this happens sometimes alone. That's why I went with the interrupt. I am trying this since last week and not getting any proper output. I double checked the pin connections with b2b and logic analyzer. Below is the slave side output. Would appreciate any help in this regard.