cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Hi,

   

in my current project I want to send a value from my Arduino UNO to my PSoC 4200.
I looked into some examples and videos but unfortunately I don't get it...

   

I suppose in my case the PSoC is the master, isn't it?
I want the received value to be stored in a variable.

   

For instance I send 0x01 from Arduino to the PSoC.
This value should be stored in a variable in PSoC so I can process it.

   

What is the easiest/beginner friendliest way to realize this?
 

0 Likes
Reply
17 Replies
Anonymous
Not applicable

Since you are initiating the communication from the UNO, the easiest way to start would be to:

   

Set the PSoC to be the Slave, and the Arduino to be the Master.

   

Then, send data from the Arduino to the PSoC, and setup the code in the PSoC to receive the data, and generate an interrupt.

   

Upon interrupt on the PSoC, process the data in the receive buffer/interrupt on the PSoC.

   

There should be a few examples of I2C communication online involving the PSoC, and there should also be examples involving interrupt handling/generation.

   

For example: http://www.cypress.com/file/63151/download This help you get started with setting up the PSoC as an I2C slave quite easily. The example is written for a PSoC 3/5, but it should be a simple matter to convert it for the PSoC 4.

0 Likes
Reply
Anonymous
Not applicable

Thank you for your repsonse.
I set up my project like in your example.

   

But I'm afraid I don't understand how to use the interrupt in this case.
I will be very glad, if you could explain this more in detail.

   

I attached the current project ot the post.
 

0 Likes
Reply
Anonymous
Not applicable

For the EZI2C you don't need to worry about the interrupt portion of communication, as that is handled by the API library.

   

If you go to the TopDesign.cysch file and right-click the EZI2C component, select "Open Datasheet" to view the documentation on the component. There should be a heading labeled "EZI2C Functional Description" on page 73; Try reading that, and then let me know if you still have questions 🙂

   

I've attached a modified code that should demonstrate slave communication of the EZI2C.

0 Likes
Reply
Anonymous
Not applicable

Thanks a lot!
I will have a look on this part of the datasheet, I skipped this part while studying the datasheet 😕

   

I will let you know if I get results 🙂

0 Likes
Reply
Anonymous
Not applicable

Sounds good 🙂

   

Yeah, the EZI2C is pretty simple to implement from looking at the datasheet; Using a custom ISR handler or other methods will be more difficult.

   

Good luck

0 Likes
Reply
Anonymous
Not applicable

Hi,

   

I have good and bad news...
The PSoC program seems to work, I tested it by using the Bridge Control Panel.
But when I send a value from Arduino to PSoC nothing happens...

   

I connected Arduino A4 to my assigned PSoC Pin for SDA (P3.4) and Arduino A5 to SCL (P3.5).
My Arduino code is following:

   

#include <Wire.h>

   

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

   

void loop() {
  Wire.beginTransmission(0x10); // Slave adress of PSoC
  Wire.write(0x01);              // Send value 0x01
  Wire.endTransmission();    // stop transmitting

   

}

0 Likes
Reply
Esteemed Contributor II

It might be that the Arduino address must be specified as an 8-bit address (Creator uses 7 bit addresses)

   

So the address must be calculated as

   

(Devaddr << 1) | ReadnWrite

   

where ReadnWrite is 0x01 for read access and 0x00 for writing.

   

So in your example

   

  Wire.beginTransmission(0x20); // Slave adress of PSoC

   

As I said: might be, but I would give it a try.

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

Hi Bob,

   

thank you for your idea, but unfortunately it does not work.

0 Likes
Reply
Anonymous
Not applicable

So I tried to locate the problem, the function "Wire.endTransmission();" returns if the transmission was successful.
The return value is 0 that equals successful transmission.

   

This is my actual Arduino code:

   

#include <Wire.h>

   

void setup() {
  Wire.begin(); // join i2c bus
  Serial.begin(9600);
}

   

byte x = 1;

   


void loop() {
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting

   

  Serial.println(Wire.endTransmission());

   

}

   

I suppose the error has to do with the PSoC and my code running on it...

0 Likes
Reply
Esteemed Contributor II

I suppose the error has to do with the PSoC and my code running on it...

   

So best should be to post actual project file again...

   

 

   

Bob

0 Likes
Reply
Anonymous
Not applicable

Here is my current project.
I also have another question, do I have to connect the GNDs of the PSoC and Arduino, that they share a common ground?

0 Likes
Reply
Anonymous
Not applicable

Soo I might have a clue what could be the problem.
I checked the clock frequencies from the PSoC and Arduino.

   

The PSoC is working with 1.5 MHz and the Arduino is working with 100kHz.
This might be problem, isn't?

0 Likes
Reply
Anonymous
Not applicable

Try setting the "Clock From Terminal" setting on the EZI2C component, and passing in a clock signal with the same speed as the Arduino I2C clock speed.

0 Likes
Reply
Anonymous
Not applicable

I tried this, but the min. frequency at PSoC for I2C is 1.5 MHz and the max. frequency for Arduino I2C is 400kHz.
 

0 Likes
Reply
Anonymous
Not applicable

Unfortunately, the Slave Clock for the I2C is limited to 1.55 MHz minimum; Page 16 of the datasheet (right-click the EZI2C component and select the datasheet)

   

It looks like you are not limited if the PSoC is the master device, but I'm assuming you wanted the Arduino to be the master...

   

According to the I2C specification, the hardware should support lower speeds depending on implementation. Are you able to clock the line in from a pin instead of from the clock?

0 Likes
Reply
Anonymous
Not applicable

I get an error code, that it is connected to a clock that is too low, it has to be at least 1.5MHz....
 

   

According to a other PSoC forum thread somebody managed it to create a working connection. #9 "I managed to create an I2C communication between arduino (master) and PSoC (slave). "

0 Likes
Reply
Anonymous
Not applicable

You could try connecting the grounds between the two boards, but I don't remember if it is required for communication.

   

In that forum post: It's hard to tell if he is using SPI, UART, or I2C or a mix...

   

He also puts at the beginning that he is using a 4 MHz clock, which since you only want a 400 kHz clock, that might be hard to do.

   

In post #12 he posts the code he got it working with for UART.

0 Likes
Reply