|
Post by tegwyntwmffat on Feb 8, 2018 12:26:52 GMT
Managed to install a replacement TC275 on my DIY PCB without breaking it Now trying to reconfigure all the code that I had running on an Arduino Due. I've got the TFT screen working nicely but having problems with Wire. Here's my code: #include "Wire.h"
TwoWire TWI;
char c;
void setup(void)
{
TWI.begin();
SerialASC.begin(115200);
SerialASC.println("Ready to test");
}
void loop(void)
{
TWI.requestFrom(43, 32); // request 32 bytes from slave device #43 FONA Data
while (TWI.available())
{
delay(10);
c = TWI.read(); // receive a byte as character
SerialASC.print(c); // print the character
}
} Compiles ok, but receives no data at all. The TC275 should be reading data from a 5V Nano, which previously worked fine with the Due through logic level shifter. I'm using pins 20 and 21 on the TC275. I'm sure I'm making a very simple mistake?
|
|
|
Post by tegwyntwmffat on Feb 8, 2018 17:11:13 GMT
I swapped the Arduino mega 2560 back onto my PCB and it worked perfectly with the following code:
#include <Wire.h>
int aa=0;
char c;
void setup(void)
{
Wire.begin();
SerialASC.begin(115200);
SerialASC.println("TEST");
}
void loop(void)
{
Wire.requestFrom(43, 32); // request 32 bytes from slave device #43 FONA Data
SerialASC.println("We never get to see this message with the TC275!!!!!");
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
SerialASC.print(c); // print the character
}
SerialASC.println("");
delay(5000);
}insert code here Then swapped back to the TC275 ..... But the code hangs just after 'Wire.requestFrom(43,32); I have almost no idea why this is happening unless it's because the power to the nano is onboard whilst the power to the TC275 is from USB. Would this be a problem?
|
|
|
Post by tegwyntwmffat on Feb 8, 2018 17:53:36 GMT
Ran the whole thing on one power supply and monitored wire request data from TFT display but just got 4 characters of garbage!
Please help!!!!!!!!!
|
|
|
Post by Admin on Feb 9, 2018 11:09:07 GMT
Your code runs OK if there is no I2C device connected. Unfortunately we do not have the "FONA" device. You could try using the bit-bashed I2C driver:
// Use SW I2C port on any two pins #include <SoftwareWire.h>
// Create Software I2C channel on pin6 (SDA) & pin 7 (SCL) // (uint8_t sdaPin, uint8_t sclPin, boolean pullups, boolean detectClockStretch) SoftwareWire SwWire( 20, 21, 0, 0); /* No pullups, no clock stretch */
int aa=0; char c;
void setup(void) {
SwWire.begin();
SerialASC.begin(115200);
SerialASC.println("TEST");
}
void loop(void)
{
SwWire.requestFrom(43, 32); // request 32 bytes from slave device #43 FONA Data
SerialASC.println("We never get to see this message with the TC275!!!!!");
while(SwWire.available()) // slave may send less than requested
{
char c = SwWire.read(); // receive a byte as character
SerialASC.print(c); // print the character
}
SerialASC.println("");
delay(5000);
}
|
|
|
Post by tegwyntwmffat on Feb 9, 2018 11:25:09 GMT
Okay thanks I will try that next week. PS. The slave device is actually just a arduino nano.
|
|
|
Post by Admin on Feb 9, 2018 11:26:46 GMT
Our standard I2C test program uses an Arduino Uno as the slave but we are only using 8 bytes.
|
|
|
Post by tegwyntwmffat on Feb 9, 2018 11:55:54 GMT
What does your standard i2c test program look like? Does it include 'request from'?
Also, I'm pretty sure all devices have to be on the same 12v / 5v bus for i2c to work properly, which means there's no opportunity to monitor through serial port on tc275 like I can with the mega? Fortunately I have tft screen working!
|
|
|
Post by tegwyntwmffat on Feb 13, 2018 12:27:20 GMT
Turns out the TC275 is wired differently than MEGA 2560 with regards to SDA / SCL. Wire library now seems to work ok
|
|
|
Post by Admin on Feb 13, 2018 12:51:08 GMT
Good! What is the wiring difference?
|
|
|
Post by tegwyntwmffat on Feb 13, 2018 15:17:15 GMT
If the chunky USB socket on the mega is pointing towards you, the first female header on the left connects to SCL and the next one to SDA. On the Due, they are SCL1 and SDA1. Just one of those annoying glitches that can cause loads of confusion!
|
|
|
Post by Admin on Feb 13, 2018 15:24:20 GMT
OK, we will put a note about this in the user manual.
|
|