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.

SPI/SSI transmission problems

Hello, 
I have tried to send data via SPI to a display using TI-RTOS. For initialisation this data is needed to be transmitted:
SS high
4µs delay
1Byte (0x02)
1Byte (0x00)
2µs delay
SS low
40µs delay
DISP high
40µs delay
then the following data 
SS is on pin PD1
DISP is on PF1
CLOCK PD0
TX PD3
I have modified the EK_TM4C123GXL.c. I changed the SS to an output.
I've tried the following programm on the tm4c123gxl board. I analysed it with a logic analyser. I hope you can help me out. 
And this is what it should look like:
Void SPI_test()
{
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x0);*/
// SS Low
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
// Delay 1ms
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 1000);
Timer_start(timer0);
SPI_Handle      handle;
SPI_Params      params;
SPI_Transaction spiTransaction;
bool ret;
SPI_Params_init(&params);
params.bitRate = 20000000;
params.mode = SPI_MASTER;
params.dataSize = 8;
params.frameFormat = SPI_POL0_PHA1;
handle = SPI_open(Board_SPI1, &params);
if (handle == NULL) {
System_printf("SPI nicht offen");
}
// Clear Flag
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0xFF);
// Delay 4us (mind. 3us)
/*Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 4);
Timer_start(timer0);*/
spiTransaction.count = SPI_MSG_LENGTH;
spiTransaction.txBuf = (Ptr)0b00100000;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
spiTransaction.count = 8;
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
//   ^
//     |
// Flag Cleared
// Delay 40 us (mind. 30 us)
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 2);
Timer_start(timer0);
// SS Low
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 40);
Timer_start(timer0);
// Enable LCD
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0xFF);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 40);
Timer_start(timer0);
// write first line
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0xFF);
// Delay 4us (mind. 3us)
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 4);
Timer_start(timer0);
spiTransaction.txBuf = (Ptr)0b11000000;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
spiTransaction.txBuf = (Ptr)reverseBits(1);
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
int line;
int i;
for(i = 0; i<50; i++)
{
spiTransaction.txBuf = (Ptr)TxMessage[i];
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
}
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
//write lines
for(line=2; line<=240; line++)
{
spiTransaction.txBuf = (Ptr)reverseBits(line);
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
for(i = 0; i<50; i++){
spiTransaction.txBuf = (Ptr)TxMessage[i+((line-1)*50)];
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
}
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
}
//write last byte
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 2);
Timer_start(timer0);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 50000);
Timer_start(timer0);
while(1){
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0xFF);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 4);
Timer_start(timer0);
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 2);
Timer_start(timer0);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 50000);
Timer_start(timer0);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0xFF);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 40);
Timer_start(timer0);
spiTransaction.txBuf = (Ptr)0b01000000;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
spiTransaction.txBuf = (Ptr)0x0;
spiTransaction.rxBuf = NULL;
ret = SPI_transfer(handle, &spiTransaction);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 2);
Timer_start(timer0);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
Timer_stop(timer0);
Timer_setPeriodMicroSecs(timer0, 50000);
Timer_start(timer0);
}
}
  • Speed is 2MHz, I wrote it false in the programm
  • Excuse me, the first Byte that should be sent is 0x20 instead of 0x02.
  • Hi,
    I don't see the problem. From the logic analyzer, I see 0x20 and 0x00 on MOSI which is what you intended. I'm I missing something else?

    Regards,
    Moses
  • Hi Moses Isang,

    The second picture in my post is how it should look like. I am not able to get this result with my programm.
    Here is how it looks like when I try to tramsmit data. This time with correct scaling and frequency.

    On this picture you can see that I tried to transmit the bits required for display initialisation via SSI3-module.

  • Hi,

      Oh i see. Looking at your SPI transfer code like the chunk below:

    spiTransaction.count = SPI_MSG_LENGTH;
    spiTransaction.txBuf = (Ptr)0b00100000;
    spiTransaction.rxBuf = NULL;
    ret = SPI_transfer(handle, &spiTransaction);
    I see you're setting the SPI transaction Tx buf to 0b00100000 which is the actual data you want to send unless you have a buffer allocated at the exact address of 0b00100000. The Tx and Rx buffer fields in the transaction structure take pointers to already allocated memory buffers and not the actual data you're trying to send. I was expecting something like:
    char buf[1] ;
    buf[0] = 0x20; //0b00100000 in Hex
    
    spiTransaction.count = 1; //Number of bytes to be transferred
    spiTransaction.txBuf = buf;
    spiTransaction.rxBuf = NULL;
    ret = SPI_transfer(handle, &spiTransaction);

    Let me know if this helps,
    Moses