Tool/software: Code Composer Studio
Hello i am using following code to send and receive data using SSI interface between master and slave, my goal is i send some value from master to slave and slave returns the value multiplied with some number.
the issue with following code is slave can receive value "ui32Message" which is 800 but the value Master receives "ui32MessageX" it stays zero.And also there is another issue when i use SSIDataGet(SSI0_BASE, &ui32Message) in one controller to recieve data and dont power the other controller(simply other controller is not connected), program gets stuck on that point next statments arent performed unless i connect it to other controller(power the other controller).
//Slave #include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/flash.h" #include "driverlib/adc.h" #include "driverlib/ssi.h" #include "drivers/buttons.h" #include "utils/uartstdio.h" /****************************************************************************** * Configure the UART and its pins. This must be called before UARTprintf(). * ******************************************************************************/ void ConfigureUART(void) { // Enable the GPIO Peripheral used by the UART. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable UART0 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // Configure GPIO Pins for UART mode. GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Use the internal 16MHz oscillator as the UART clock source. UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // Initialize the UART for console I/O. UARTStdioConfig(0, 115200, 16000000); } /*************************************** * Main function, program entry point. * ***************************************/ int main(void) { uint32_t ui32Message = 0; uint32_t ui32MessageX = 0; // Set the clocking to run at 50 MHz from the PLL. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0RX); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_SLAVE, 10000, 16); SSIEnable(SSI0_BASE); // Initialize the UART and configure it ConfigureUART(); UARTprintf("\n******************\n* SSI slave logs *\n******************\n"); while(1) { UARTprintf("\n ui32Message \n"); SSIDataGet(SSI0_BASE, &ui32Message); UARTprintf("%d",ui32Message); UARTprintf("\n ui32Message recieved \n"); SysCtlDelay(SysCtlClockGet()/100); while(SSIBusy(SSI0_BASE)); ui32MessageX=ui32Message+2; UARTprintf("%d",mx); SSIDataPut(SSI0_BASE, ui32MessageX); while(SSIBusy(SSI0_BASE)); UARTprintf("\------ui32MessageX Sent-----\n"); } }
// Master #include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/flash.h" #include "driverlib/adc.h" #include "driverlib/ssi.h" #include "drivers/buttons.h" #include "utils/uartstdio.h" /****************************************************************************** * Configure the UART and its pins. This must be called before UARTprintf(). * ******************************************************************************/ void ConfigureUART(void) { // Enable the GPIO Peripheral used by the UART. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable UART0 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // Configure GPIO Pins for UART mode. GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Use the internal 16MHz oscillator as the UART clock source. UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // Initialize the UART for console I/O. UARTStdioConfig(0, 115200, 16000000); } uint32_t ui32Message = 0; unit32_t ui32MessageX= 0; int main(void) { // Set the clocking to run at 50 MHz from the PLL. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; // HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0xFF; // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA5_SSI0TX); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_3 | GPIO_PIN_2); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 10000, 16); SSIEnable(SSI0_BASE); // Initialize the UART and configure it ConfigureUART(); UARTprintf("\n******************\n* SSI Master logs *\n******************\n"); while(1) { ui32Message = 800; SSIDataPut(SSI0_BASE, ui32Message); while(SSIBusy(SSI0_BASE)); UARTprintf("\ui32Message Sent\n"); SysCtlDelay(SysCtlClockGet()/100); SSIDataGet(SSI0_BASE, &ui32MessageX); UARTprintf("%d",ui32MessageX); UARTprintf("\n ui32Message received \n"); while(SSIBusy(SSI0_BASE)); } }