Using a different i2c bus on each of two cogs?
geeklifter
Posts: 4
This might be a silly question, so please feel free to point out obvious problems (I'm new to multi-core and i2c protocol but I'm enjoying myself).
Can a different i2c bus be created on different cogs? By that I mean one i2c bus per cog with 2 or more cogs. I've been trying this purely for my own education, but they seem to interfere with each other. When I use any function that does NOT create an i2c bus, the code works fine (i.e. I can blink an LED and get sensor values with different cogs just fine). And when I run the functions on the same cog, they also work fine with separate buses (similar to the great example provided in the DIY I2C section of the parallax site). However, when I try to run the sensor functions from different cogs the code runs but does not give realistic or consistent values.
Something like this:
int *cog1 = cog_run(&get_sensor1_values, 20);
int *cog2 = cog_run(&get_sensor2_values, 20);
int main()
{
while(1)
{
...print some volatile values that are assigned by the other cogs...
}
}
void get_sensor1_values()
{
...
i2c *sensor1Bus = i2c_newbus(S1_SCL_PIN,S2_SDA_PIN,0);
while(1)
{
...get values...
}
}
void get_sensor2_values()
{
...
i2c *sensor2Bus = i2c_newbus(S2_SCL_PIN,S2_SDA_PIN,0);
while(1)
{
...get values...
}
}
Any major problems with this?
Thanks!
Tom the aspiring programmer
Can a different i2c bus be created on different cogs? By that I mean one i2c bus per cog with 2 or more cogs. I've been trying this purely for my own education, but they seem to interfere with each other. When I use any function that does NOT create an i2c bus, the code works fine (i.e. I can blink an LED and get sensor values with different cogs just fine). And when I run the functions on the same cog, they also work fine with separate buses (similar to the great example provided in the DIY I2C section of the parallax site). However, when I try to run the sensor functions from different cogs the code runs but does not give realistic or consistent values.
Something like this:
int *cog1 = cog_run(&get_sensor1_values, 20);
int *cog2 = cog_run(&get_sensor2_values, 20);
int main()
{
while(1)
{
...print some volatile values that are assigned by the other cogs...
}
}
void get_sensor1_values()
{
...
i2c *sensor1Bus = i2c_newbus(S1_SCL_PIN,S2_SDA_PIN,0);
while(1)
{
...get values...
}
}
void get_sensor2_values()
{
...
i2c *sensor2Bus = i2c_newbus(S2_SCL_PIN,S2_SDA_PIN,0);
while(1)
{
...get values...
}
}
Any major problems with this?
Thanks!
Tom the aspiring programmer
Comments
you need to seprate the ic2 busses ....by that i mean the pins.
there's no way you can run 2 separate busses from the same pin. (separate/same being the biggest issue)
since the cogs run round robin they will keep hitting the same pins with conflicting data.
your code says IF I read it right...both are connected to pin0?
after that...logically it SHOULD work.
I'm new to prop fun myself and i didn't do any i2c stuff when I did BS-1/2 so.....
But I'm looking into it myself.
I tend to agree. and actually.....
I intend to have 3-4 i2c buses myself as part of a home automation project I'm beginning with a couple of p8x32a units i have.
Ok at this point in my prop devolpment that's waaaay ahead of me in execution. But, where is this discussed so i can look at it?
I found http://learn.parallax.com/propeller-c-simple-protocols/full-duplex-serial
I get that and love it. (Simpler than I expected) but, not able to make it i2c relevant.
That said, some I2C objects might be easier to get working than others (or more to the point, some are better than others). I'd try as many as you can from OBEX to see what works.