- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone!
I'm experiencing issues with SPI communication. The objective of my project is to display the temperature on the LCD screen, using PSoC as SPI Master, and a TC72 as SPI Slave. My project is joined to this message, and so are the datasheets of SPIM component and TC72.
Starting data tranfert.
I do not understand how to initiate the data tranfer from the SPIS to the SPIM. According to the TC72 datasheet I think SPIS will send data if it receives a high level on « CE », but I don’t know how to send it. I’ve trying to send not(SS) as SS seems to be Low when MISO data are received, but it’s not a good solution apparently. I didn’t find code example.
When I observe the signals, SCLK is always low, SS is always high so CE is always low. Well, you can imagine that nothing else happens!
Receiving data
Once I’ll be able to receive data from TC72 (hopefully), I guess I’ll just have to read the SPIM Rx buffer and to translate it from Hexadecimal to temperature following the TC072 datasheet.
Material:
PSoC5LP CY8KIT-050
PSoC Creator 4.2
Component : SPIM v2.50
Pins connection:
SPIM SCLK --> TC072 SCLK
SPIM MOSI --> TC072 SDI
TC072 SDO --> SPIM MISO
Not(SPIM SS) -->TC072 CE
5V --> TC072 VDD
GND --> TC072 GND
Thanks a lot for your help,
Best regards,
Emma.
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Emma-san,
I tried with CY8CKIT-059 with following main.c
when I used TeraTerm, at least it did not block
main.c
========================
/* ========================================
* PSoC Project
* Using PSoC as SPI Master
* Using TC072 as SPI Slave
* Objective : have a temperature display
* ========================================
*/
#include "project.h"
#include "stdio.h"
#define USE_UART 0
#if USE_UART
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_PutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(100) ;
print("\033[2J") ; /* clear screen */
CyDelay(100) ;
}
#endif
#define TIMEOUT_LIMIT 5000
uint8 rx;
int main(void)
{
uint32_t timeout_count = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
#if USE_UART
UART_Start() ;
cls() ;
print("SPIM temp\n") ;
#else
/*starting LCD + display*/
LCD_Start();
LCD_Position(0u,0u);
LCD_PrintString("SPIM temp");
LCD_Position(1u,0u);
LCD_PrintString("let's gooo");
CyDelay(3000u);
#endif
/*starting and enable SPIM*/
SPIM_1_Start();
#if USE_UART
print("Temperature : ") ;
#else
//LCD Display
LCD_ClearDisplay();
LCD_Position(0u,0u);
LCD_PrintString("Temperature : ");
#endif
//1.SPIM wake-up
//2.Waiting for Rx to receive data
//3.Store the result
//4.SPIM sleep, cleaning of Rx and Tx buffers
//5.Affichage
for(;;)
{
//1
SPIM_1_Wakeup();
CyDelay(2000u);
// 1.5
SPIM_1_WriteByte(0x00) ;
//2
timeout_count = 0 ;
while(SPIM_1_GetRxBufferSize() == 0) {
timeout_count++ ;
if (timeout_count >= TIMEOUT_LIMIT) {
print("Time Out!\n") ;
break ;
}
}
// while(!( SPIM_1_ReadRxStatus() & SPIM_1_STS_RX_FIFO_FULL));
//3
rx = SPIM_1_ReadRxData();
//4
SPIM_1_Sleep();
SPIM_1_ClearRxBuffer();
SPIM_1_ClearTxBuffer();
//5
#if USE_UART
sprintf(str, "%d\n", rx) ;
print(str) ;
#else
LCD_Position(1u,2u);
LCD_PrintHexUint8(rx);
#endif
CyDelay(2000u);
}
}
========================
Best Regards,
17-Jan-2020
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I think that SCLK of SPIM is generated when SPIM is sending data (and also receiving data).
So how about adding
SPIM_1_WriteTxData(0x00) ;
before
while(!( SPIM_1_ReadRxStatus() & SPIM_1_STS_RX_FIFO_FULL));
So it will look like
================
for(;;)
{
//1
SPIM_1_Wakeup();
CyDelay(2000u);
// 1.5
SPIM_1_WriteTxData(0x00) ; // send a dummy byte (meantime receive a byte)
//2
while(!( SPIM_1_ReadRxStatus() & SPIM_1_STS_RX_FIFO_FULL));
//3
rx = SPIM_1_ReadRxData();
//4
SPIM_1_Sleep();
SPIM_1_ClearRxBuffer();
SPIM_1_ClearTxBuffer();
//5
LCD_Position(1u,2u);
LCD_PrintHexUint8(rx);
CyDelay(2000u);
}
================
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi moto,
Thanks for your answer . I tried but the condition while(!( SPIM_1_ReadRxStatus() & SPIM_1_STS_RX_FIFO_FULL)); is never fulfilled. Also, if I comment this line, nothing changes: my display is always "00", SCLK and CE are both flat and Low...
Also, I still wonder where I could connect my CE pin (TC72), because maybe not(SS) is not a good solution...
another idea?
Emma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Emma-san,
I would use
while (SPIM_1_GetRxBufferSize() == 0) ;
meantime, as this could cause dead lock I would do something like...
=======================
#define TIMEOUT_LIMIT 5000
uint32_t timeout_count = 0 ;
timeout_count = 0 ;
while(SPIM_1_GetRxBufferSize() == 0) {
timeout_count++ ;
if (timeout_count >= TIMEOUT_LIMIT) {
break ; // or return time out
}
CyDelayUs(1) ;
}
=======================
Best Regards,
17-Jan-2020
Motoo Tanaka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Motoo,
Unfortunately I still have the same result... Feel free to share other ideas Hope I'll find something new!
Best Regards,
Emma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Emma-san,
I tried with CY8CKIT-059 with following main.c
when I used TeraTerm, at least it did not block
main.c
========================
/* ========================================
* PSoC Project
* Using PSoC as SPI Master
* Using TC072 as SPI Slave
* Objective : have a temperature display
* ========================================
*/
#include "project.h"
#include "stdio.h"
#define USE_UART 0
#if USE_UART
#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str)
{
UART_PutString(str) ;
}
void cls(void)
{
print("\033c") ; /* reset */
CyDelay(100) ;
print("\033[2J") ; /* clear screen */
CyDelay(100) ;
}
#endif
#define TIMEOUT_LIMIT 5000
uint8 rx;
int main(void)
{
uint32_t timeout_count = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
#if USE_UART
UART_Start() ;
cls() ;
print("SPIM temp\n") ;
#else
/*starting LCD + display*/
LCD_Start();
LCD_Position(0u,0u);
LCD_PrintString("SPIM temp");
LCD_Position(1u,0u);
LCD_PrintString("let's gooo");
CyDelay(3000u);
#endif
/*starting and enable SPIM*/
SPIM_1_Start();
#if USE_UART
print("Temperature : ") ;
#else
//LCD Display
LCD_ClearDisplay();
LCD_Position(0u,0u);
LCD_PrintString("Temperature : ");
#endif
//1.SPIM wake-up
//2.Waiting for Rx to receive data
//3.Store the result
//4.SPIM sleep, cleaning of Rx and Tx buffers
//5.Affichage
for(;;)
{
//1
SPIM_1_Wakeup();
CyDelay(2000u);
// 1.5
SPIM_1_WriteByte(0x00) ;
//2
timeout_count = 0 ;
while(SPIM_1_GetRxBufferSize() == 0) {
timeout_count++ ;
if (timeout_count >= TIMEOUT_LIMIT) {
print("Time Out!\n") ;
break ;
}
}
// while(!( SPIM_1_ReadRxStatus() & SPIM_1_STS_RX_FIFO_FULL));
//3
rx = SPIM_1_ReadRxData();
//4
SPIM_1_Sleep();
SPIM_1_ClearRxBuffer();
SPIM_1_ClearTxBuffer();
//5
#if USE_UART
sprintf(str, "%d\n", rx) ;
print(str) ;
#else
LCD_Position(1u,2u);
LCD_PrintHexUint8(rx);
#endif
CyDelay(2000u);
}
}
========================
Best Regards,
17-Jan-2020
Motoo Tanaka