- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I would like to have Arduino send short commands to PSoC 042 BLE (like "start" , "sleep" etc) via SPI communication.
If someone has done something similar before, I would be extremely grateful if he could provide me with hints or some kind of guidance. Is there something particular I should be aware of?
The Arduino code is as simple as that:
#include <SPI.h>
void setup()
{
SPI.beginTransaction (SPISettings (4000000, MSBFIRST, SPI_MODE0)); // 4 MHz clock
}
void loop()
{
digitalWrite (SS, LOW); // assert Slave Select
for (const char * p = "Hello" ; c = *p; p++)
{
SPI.transfer (c);
}
digitalWrite (SS, HIGH); // de-assert Slave Select
delay(1500); // wait a bit before sending it again
}
For the PSoC part, I have used a SCB SPI Slave component and I have assigned the pins P0.0...P0.3.
How can I make the PSoC understand that the time has come to receive a message, and how to receive it?
Any thoughts, insights or hints are gratefully accepted.
Kind regards,
Nikos
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The PSoC SPI slave will receive the slave select signal, and from there read the data thats clocked in. When a byte has received, it can fire an interrupt. Just listen to that. Maybe read the SCP SPI data sheet first, too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your answer. I have read te data sheet and a few examples too but I am still lost!
Say that I have named the SPI block as "SPI", then the data you are saying are stored in SPI_mosi_s_Read() ? because when I read from that I only get 01 as a result in my LCD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are looking for SCB_SpiUartReadRxData(). The SPI slave puts the data it has received in its internal FIFO, and this function retrieves the first element from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nikos,
for text messages standard UART is more appropriate. Can you stay with UART?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Yes I could stay with UART and in fact I am going to try it right now! Thank you for your comment!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I still haven't managed to make it work.
Do you have any tutorial or example that you could share please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nikolaus,
Attached basic UART_Rx example. Modify code for your needs
http://www.cypress.com/file/208726/download
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much for your help Odissey1.
I managed to create an I2C communication between arduino (master) and PSoC (slave).
I will now try to create the UART based communication based on the example you shared! Thanks again
Nikos
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Can you explain how you managed to create an i2c interface between Arduino and PSoC?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Odissey1,
I am trying to modify the code you provided me with, but this command
Rx_Int_StartEx(MyRxInt);
says that is invalid in C99 and creates an error when building the project.
Any clues?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
don't bother, it was a typo!!
the correct command is
RX_Int_StartEx(MyRxInt); //capital "X"
I will post the code once it is functioning
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, so I finally did it with UART.
I based my code to UART_RX example. Now I can send commands from my arduino to my PSoC using Serial.write(" ") .
baud rate is at 57600 in both boards, when PSoC understands that a message is incoming it receives it and creates a string that contains that message.
Here is the code, I hope it will help some people.
#include <device.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
char8 ch; /* Data received from the Serial port */
char strmsg[64]; /* string that holds commands from master*/
int i = 0; /* for counting */
CyGlobalIntEnable; /* Enable all interrupts by the processor. */
LCD_Char_1_Start();
UART_1_Start();
while(1)
{
/* Check the UART status */
ch = UART_1_GetChar();
/* hold this char as the first char of our string */
strmsg[0] = ch;
/* If byte received */
if(ch > 0u)
{
for(i = 1; i<=8; i++) /* fill the rest of the string */
{
strmsg = UART_1_GetChar();
}
LCD_Char_1_Position(0u, 0u);
LCD_Char_1_PrintString(strmsg); /* Print the received string */
/* print the size of the buffer on the line below - optional */
//LCD_Char_1_Position(1u, 0u);
//LCD_Char_1_PrintInt8(UART_1_GetRxBufferSize()); /* Prints the count in the LCD */
}
UART_1_ClearRxBuffer(); /* clear buffer */
CyDelay(1000); /* wait a sec */
LCD_Char_1_ClearDisplay(); /* clear LCD */
}
}