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(¶ms);
params.bitRate = 20000000;
params.mode = SPI_MASTER;
params.dataSize = 8;
params.frameFormat = SPI_POL0_PHA1;
handle = SPI_open(Board_SPI1, ¶ms);
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);
}
}