1 Reply Latest reply on Jan 8, 2018 9:10 PM by msur

    porting PSOC4 SPI master code to PSOC6 to drive a TFT display

    GerrikoIoT

      I am trying to drive a TFT screen off my PSoC6 Pioneer board.

       

      I found some code which does the job on my PSoc4 BLE board and thought it would simply work if I copy across to PSoC6, but this is proving not that simple. So I thought to reach out to see what tips people can offer.

       

      So in PSoC4 TopDesign I have the following:

       

       

      In advanced settings I have:

       

       

      Now in PSoC6 TopDesign I have set the following:

       

      If I have made any errors defining my PSoC6 SPI hardware block, please let me know.

       

      Then within the code, I noticed a few subtle changes and wondered how best to adapt.

       

      For example, in PSoC4 code, the output pin defined as TFTDC is written to using TFTDC_Write(0).

      To achieve the same in PSoC6, I found that I need to use: Cy_GPIO_Write(TFTDC_0_PORT, TFTDC_0_NUM, 0)

       

      Now here is where I am confused: In PSoC4 to write data or send command via SPI you use: SPIM_WriteTxData(cmd) where cmd is defined as type uint8_t

      But in PSoC6 I see you would have the cmd parameter defined as type uint32_t.

       

      So what other API changes have been made.

       

      Any tips gladly appreciated as cannot get this to work.

        • 1. Re: porting PSOC4 SPI master code to PSOC6 to drive a TFT display
          msur

          Hello GerrikoIoT,

           

          I don't see any issue in the hardware setting. So I guess it should work with PSoC 6, if the PSoC 4 configuration worked.

           

          Now to the code, most if not all the PDL APIs take uint32 as input in PSoC 6. This is something we started with PSoC 6. As with any 32-bit processor, it would be more code and performance efficient, if we handle/process data in native (32-bit) data widths. That said, even though the SPI_Write() API takes a 32-bit word as input, it only places the LSB x-bits (8-bits in your case) configured as the SPI data width into the Tx FIFO.

           

          You might want to consider the below example for issuing a command/data write to the display controller:

           

          #define Display_SendData(d) SPIm_Display_WriteArrayBlocking(&d, 1)

           

          void Display_SendCommand(unsigned char c)

          {

              //Make sure SPI Tx is complete before toggling data/cmd pin.

              while((SPIm_Display_GetNumInTxFifo() + Cy_SCB_GetTxSrValid(SPIm_Display_HW)) != 0);

              Cy_GPIO_Clr(Pin_Disp_DnC_0_PORT, Pin_Disp_DnC_0_NUM);

           

              SPIm_Display_WriteArrayBlocking(&c, 1);

           

              //Make sure SPI Tx is complete before toggling data/cmd pin.

              while((SPIm_Display_GetNumInTxFifo() + Cy_SCB_GetTxSrValid(SPIm_Display_HW)) != 0);

              Cy_GPIO_Set(Pin_Disp_DnC_0_PORT, Pin_Disp_DnC_0_NUM);

          }

           

          void Display_SendData_Chunk(unsigned char *d, uint32 len)

          {

              SPIm_Display_WriteArrayBlocking(d, len);

          }

           

          Note that you can use either SPIm_Display_WriteArrayBlocking() or SPIm_Display_Write(). But when using SPIm_Display_Write API you need to make sure the data is placed in the FIFO successfully by using this - "while (SPIm_Display_Write(d) == 0);"

           

          The send data chunk can be used to send a chunk of continuous bytes data to the display.

           

          Let me know if this answers your questions.

           

          Regards,

          Meenakshi Sundaram R