energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
795 stars 671 forks source link

I2C Wire Library not working with G2553 LP #486

Closed mringwal closed 8 years ago

mringwal commented 9 years ago

I don't see anything happen on pins 9/10 (p2.1/p2.2) or 14/15 (p1.6/p1.7) when running the master_write example from the Wire library.

Same example with the 5529LP has a working I2C on 14/15 (p3.0/p3.1).

It would be great, if the details of the Wire lib (it's not on the 9/10 as shown on the Booster Pack docu) could be added somewhere.

(I've connected a Logic16 to check the output)

rei-vilo commented 9 years ago

How surprising! Can you share the code? Don't forget about external pull-up resistors. 10 kΩ are fine.

mringwal commented 9 years ago

It's just the master_write code from the examples. I have the pull ups and the same "booster pack" works (at least there's an i2c signal) with the 5529 LP

rei-vilo commented 9 years ago

The I²C bus on pins 9/10 isn't available for the MSP430G2553.

You need to use the software I²C library instead.

mringwal commented 9 years ago

I understand that i2c isn't available on 9/10. On the 5529LP it is available (without additional config) on 14/15. I assumed that it would also be available on 14/15 on the G2553.

rei-vilo commented 9 years ago

Yes, that's the case.

The I²C bus uses pins 14/15 on the MSP430G2553 and I'm using them on a daily basis.

mringwal commented 9 years ago

Ok, so that's what's not working. I don't see any data on 14/15 on the MSP-EXP430G2 with G2553 chip using Energia 13

rei-vilo commented 9 years ago

Ok, now try the very same sketch with the previous release of Energia 0101E0012.

mringwal commented 9 years ago

Energia 12, same behavior -> nothing happens. Can I use the twi implementation directly?

mringwal commented 9 years ago

I just realized that there also might be a hardware problem with this particular LP. I'll try once more with a second board (should be still be packaged up).

robertinant commented 9 years ago

@mringwal were you able to get this working?

mringwal commented 9 years ago

Thanks for reminding. So, I've just unwrapped another 430G2 and uploaded the master_writer example. Same result: I don't see anything on 14/15 yet.

I did solve my actual problem using Rei's Software I2C, but using the lower level i2c routines directly. My I2c chip requires to check ACK/NACK after writing the address. I didn't see how to do that with the original Wire interface.

So, if somebody has a few minutes of time and two extra pull-ups to VCC, please check i2c on a G2 board. .. and/or.. add the I2C docu from Arduino.cc plus mention where/how it can be used.

robertinant commented 9 years ago

Will try reproduce on monday.

robertinant commented 9 years ago

I just tried to reproduce but it's working for me. Make sure that you remove J5 (P1.6) to disable the connection to LED2 which interferes with SCL.

mringwal commented 9 years ago

Hi. Confirmed to be working after removing JP (P1.6), thanks for this little detail!

So the new "issue" is: where/how should have I read that:

While technically obvious/trivial, almost everyone that will try to use i2c will just fail and be at the mercy of an issue tracker (filing non-issues) or the 430oh IRC channel (very helpful), or just complain on their favorite communication channel.

rei-vilo commented 9 years ago

Please refer to the pins maps specifically designed for Energia.

for MSP430G2, http://energia.nu/pin-maps/guide_msp430g2launchpad/

mringwal commented 9 years ago

Thank you! I remember that I was directed to this page after I couldn't get UART debut output as the jumpers had to be "rotated". Can we add a short paragraph on i2c there? Like..

== Wire interface, I2C == Please note that the I2C peripheral is on pins 14/15 instead of pin 9/10 as indicated on newer LaunchPad BoosterPack Pinouts. Please refer to the pin mapping here. Also, LED2 is controlled via P1.6, which is used for I2C SCL. too. To use I2C, please remove jumper JP 5/P1.6

rei-vilo commented 9 years ago

Unfortunately, I don't have access to the wiki section. But everything is clearly stated on the map:

capture 2014-10-16 a 12 52 35

mringwal commented 9 years ago

Robert has :0)

I'm not saying the map is incorrect. It is correct.

spirilis commented 9 years ago

Yeah, probably worth a footnote on the Energia page. paging @robertinant ... Right under the "Serial port communication, Hardware UART" section near the bottom, something like this-

I2C support

robertinant commented 9 years ago

Website has been updated with a note on I2C.

mringwal commented 9 years ago

Thanks!

martin43211 commented 8 years ago

Hey guys, sorry to warm up this post again but I experience a problem with the I2C device addresses ALTHOUGH I took the jumper from Pin 1.6 to the LED out. I connected a GY-521 gyrosensor to Pin1.6 (SCA) and Pin1.7 (SCL). Pin AD0 is going to GND. VCC to VCC. I use the I2C scanner code from: http://playground.arduino.cc/Main/I2cScanner

I get this output in the Serial Monitor: Scanning...Found Address 0x01, Scanning... I2C device found at address 0x01 ! I2C device found at address 0x02 ! I2C device found at address 0x03 ! I2C device found at address 0x04 ! I2C device found at address 0x05 ! I2C device found at address 0x06 ! I2C device found at address 0x07 ! I2C device found at address 0x08 ! I2C device found at address 0x09 ! I2C device found at address 0x0A ! I2C device found at address 0x0B ! I2C device found at address 0x0C ! I2C device found at address 0x0D ! I2C device found at address 0x0E ! I2C device found at address 0x0F ! I2C device found at address 0x10 ! I2C device found at address 0x11 ! I2C device found at address 0x12 ! I2C device found at address 0x13 ! I2C device found at address 0x14 ! I2C device found at address 0x15 ! I2C device found at address 0x16 ! I2C device found at address 0x17 ! I2C device found at address 0x18 ! I2C device found at address 0x19 ! I2C device found at address 0x1A ! I2C device found at address 0x1B ! I2C device found at address 0x1C ! I2C device found at address 0x1D ! I2C device found at address 0x1E ! I2C device found at address 0x1F ! I2C device found at address 0x20 ! I2C device found at address 0x21 ! I2C device found at address 0x22 ! I2C device found at address 0x23 ! I2C device found at address 0x24 ! I2C device found at address 0x25 ! I2C device found at address 0x26 ! I2C device found at address 0x27 ! I2C device found at address 0x28 ! I2C device found at address 0x29 ! I2C device found at address 0x2A ! I2C device found at address 0x2B ! I2C device found at address 0x2C ! I2C device found at address 0x2D ! I2C device found at address 0x2E ! I2C device found at address 0x2F ! I2C device found at address 0x30 ! I2C device found at address 0x31 ! I2C device found at address 0x32 ! I2C device found at address 0x33 ! I2C device found at address 0x34 ! I2C device found at address 0x35 ! I2C device found at address 0x36 ! I2C device found at address 0x37 ! I2C device found at address 0x38 ! I2C device found at address 0x39 ! I2C device found at address 0x3A ! I2C device found at address 0x3B ! I2C device found at address 0x3C ! I2C device found at address 0x3D ! I2C device found at address 0x3E ! I2C device found at address 0x3F ! I2C device found at address 0x40 ! I2C device found at address 0x41 ! I2C device found at address 0x42 ! I2C device found at address 0x43 ! I2C device found at address 0x44 ! I2C device found at address 0x45 ! I2C device found at address 0x46 ! I2C device found at address 0x47 ! I2C device found at address 0x48 ! I2C device found at address 0x49 ! I2C device found at address 0x4A ! I2C device found at address 0x4B ! I2C device found at address 0x4C ! I2C device found at address 0x4D ! I2C device found at address 0x4E ! I2C device found at address 0x4F ! I2C device found at address 0x50 ! I2C device found at address 0x51 ! I2C device found at address 0x52 ! I2C device found at address 0x53 ! I2C device found at address 0x54 ! I2C device found at address 0x55 ! I2C device found at address 0x56 ! I2C device found at address 0x57 ! I2C device found at address 0x58 ! I2C device found at address 0x59 ! I2C device found at address 0x5A ! I2C device found at address 0x5B ! I2C device found at address 0x5C ! I2C device found at address 0x5D ! I2C device found at address 0x5E ! I2C device found at address 0x5F ! I2C device found at address 0x60 ! I2C device found at address 0x61 ! I2C device found at address 0x62 ! I2C device found at address 0x63 ! I2C device found at address 0x64 ! I2C device found at address 0x65 ! I2C device found at address 0x66 ! I2C device found at address 0x67 ! I2C device found at address 0x68 ! I2C device found at address 0x69 ! I2C device found at address 0x6A ! I2C device found at address 0x6B ! I2C device found at address 0x6C ! I2C device found at address 0x6D ! I2C device found at address 0x6E ! I2C device found at address 0x6F ! I2C device found at address 0x70 ! I2C device found at address 0x71 ! I2C device found at address 0x72 ! I2C device found at address 0x73 ! I2C device found at address 0x74 ! I2C device found at address 0x75 ! I2C device found at address 0x76 ! I2C device found at address 0x77 ! I2C device found at address 0x78 ! I2C device found at address 0x79 ! I2C device found at address 0x7A ! I2C device found at address 0x7B ! I2C device found at address 0x7C ! I2C device found at address 0x7D ! I2C device found at address 0x7E ! done

The GY-521 has pull-up resistors on-board which I measured: The voltage from SDA-GND and SDL-GND is 3.3V. Does anybody have a suggestion how to find my mistake? Cheers and thanks in advance, M

StefanSch commented 8 years ago

Hi, with Energia17 the default pins for the I2C have been changed to pin 9 and 10 so that it is consistent for all Launchpads. Unfortunately the pin map picture for this Launchpad have not been updated so far. So either connect to the pins 9 and 10 or switch to the alternate I2C bus with Wire.begin(0); // join i2c bus (address optional for master) or setModule(0);

rei-vilo commented 8 years ago

I've updated the pins map some time ago but it hasn't been published.

launchpads msp430g2 pins maps

StefanSch commented 8 years ago

Yes, I just sent a note again and requested the update.

martin43211 commented 8 years ago

Hi Stefan and rei-vilo, thanks for your fast replies and inputs. So I tried switching the SDA and SCL ports from pins 1.7 and 1.6, respectively to pins 2.2 and 2.1 and did NOT change the Wire.begin(); in the example from: http://playground.arduino.cc/Main/I2cScanner Then the I2C scanner gives out this:

I2C Scanner Scanning... Unknow error at address 0x01 Unknow error at address 0x02 Unknow error at address 0x03 Unknow error at address 0x04 Unknow error at address 0x05 Unknow error at address 0x06 Unknow error at address 0x07 Unknow error at address 0x08 Unknow error at address 0x09 Unknow error at address 0x0A Unknow error at address 0x0B Unknow error at address 0x0C Unknow error at address 0x0D Unknow error at address 0x0E Unknow error at address 0x0F Unknow error at address 0x10 Unknow error at address 0x11 Unknow error at address 0x12 Unknow error at address 0x13 Unknow error at address 0x14 Unknow error at address 0x15 Unknow error at address 0x16 Unknow error at address 0x17 Unknow error at address 0x18 Unknow error at address 0x19 Unknow error at address 0x1A Unknow error at address 0x1B Unknow error at address 0x1C Unknow error at address 0x1D Unknow error at address 0x1E Unknow error at address 0x1F Unknow error at address 0x20 Unknow error at address 0x21 Unknow error at address 0x22 Unknow error at address 0x23 Unknow error at address 0x24 Unknow error at address 0x25 Unknow error at address 0x26 Unknow error at address 0x27 Unknow error at address 0x28 Unknow error at address 0x29 Unknow error at address 0x2A Unknow error at address 0x2B Unknow error at address 0x2C Unknow error at address 0x2D Unknow error at address 0x2E Unknow error at address 0x2F Unknow error at address 0x30 Unknow error at address 0x31 Unknow error at address 0x32 Unknow error at address 0x33 Unknow error at address 0x34 Unknow error at address 0x35 Unknow error at address 0x36 Unknow error at address 0x37 Unknow error at address 0x38 Unknow error at address 0x39 Unknow error at address 0x3A Unknow error at address 0x3B Unknow error at address 0x3C Unknow error at address 0x3D Unknow error at address 0x3E Unknow error at address 0x3F Unknow error at address 0x40 Unknow error at address 0x41 Unknow error at address 0x42 Unknow error at address 0x43 Unknow error at address 0x44 Unknow error at address 0x45 Unknow error at address 0x46 Unknow error at address 0x47 Unknow error at address 0x48 Unknow error at address 0x49 Unknow error at address 0x4A Unknow error at address 0x4B Unknow error at address 0x4C Unknow error at address 0x4D Unknow error at address 0x4E Unknow error at address 0x4F Unknow error at address 0x50 Unknow error at address 0x51 Unknow error at address 0x52 Unknow error at address 0x53 Unknow error at address 0x54 Unknow error at address 0x55 Unknow error at address 0x56 Unknow error at address 0x57 Unknow error at address 0x58 Unknow error at address 0x59 Unknow error at address 0x5A Unknow error at address 0x5B Unknow error at address 0x5C Unknow error at address 0x5D Unknow error at address 0x5E Unknow error at address 0x5F Unknow error at address 0x60 Unknow error at address 0x61 Unknow error at address 0x62 Unknow error at address 0x63 Unknow error at address 0x64 Unknow error at address 0x65 Unknow error at address 0x66 Unknow error at address 0x67 Unknow error at address 0x68 Unknow error at address 0x69 Unknow error at address 0x6A Unknow error at address 0x6B Unknow error at address 0x6C Unknow error at address 0x6D Unknow error at address 0x6E Unknow error at address 0x6F Unknow error at address 0x70 Unknow error at address 0x71 Unknow error at address 0x72 Unknow error at address 0x73 Unknow error at address 0x74 Unknow error at address 0x75 Unknow error at address 0x76 Unknow error at address 0x77 Unknow error at address 0x78 Unknow error at address 0x79 Unknow error at address 0x7A Unknow error at address 0x7B Unknow error at address 0x7C Unknow error at address 0x7D Unknow error at address 0x7E No I2C devices found

When I switch back to the old configuration (Pin1.7 -> SDA and Pin 1.6 -> SCL, and Jumper from Pin 1.6 to LED2 removed ) and include change the Wire.begin() to Wire.begin(0), I get the same output as in my first post:

Scanning... I2C device found at address 0x01 ! ...you get the picture.

Do you have any other suggestions? I have a GY-521 connected to the MSP430. The AD0 pin is connected to ground (then the device should have the address 0x68) and there are pull-up resistors on-board. It perfectly works with an Arduino Uno

martin43211 commented 8 years ago

Even if I directly ground the SCL and SDA pins, there should at least, no I2C device should be found but I still get the message, that all addresses are ocupied with I2C devices (same message as in my first post)

simseve commented 8 years ago

Hi Martin, did you solve? I have same exact issue. I2C scanner works in Arduino but not on the MSP430 and behaves exactly like you described.

martin43211 commented 8 years ago

Hi simseve, unfortunately no. I could not figure it out. Did you try to attach the MSP to the Arduino and use the I2C scanner? I tried but the arduino does not 'see' the MSP when they are connected via I²C. Does anybody else have an idea

simseve commented 8 years ago

Hi, I just saw that Wire library folder was empty on my Mac. I'm downloading the library again.

martin43211 commented 8 years ago

Hey, the Wire.h and Wire.cpp are in the MPS430/cores/ folder and I found that this should not be a problem. Moved them to MSP430/libraries/Wire and still there is no effect except that I can now add the Wire.h library in Energia via Sketch -> Import Libraries which was not possible before. Unfortunately I have no idea anymore and will use the Arduino for now since I just started with µCs and don't want to frustrate myself right from the start. Would be interested though if you find a solution.

martin43211 commented 8 years ago

The only last thing I found is that, when I connect the SCL and SDA pins to GND and VCC, respectively, I get different outputs of the I2C scanner. For the connection to GND, I get:

Unknown error at address ... (a long list with all addresses)

and when I connect them both to VCC:

I2C device found at address ... (a long list with all addresses)

StefanSch commented 8 years ago

Did some more test and found that this might never has worked. Just commited a version which does support the scanning of the I2C slaves: https://github.com/energia/Energia/pull/868/files

StefanSch commented 8 years ago

fix is available with pull request #868

simseve commented 8 years ago

Thanks StefanSch. How can I try your mods on my side (procedure to include your changes)?thanks

StefanSch commented 8 years ago

You can download the raw file from git hub and replace it within your energia system: https://raw.githubusercontent.com/energia/Energia/issue_486/hardware/msp430/cores/msp430/twi.c https://raw.githubusercontent.com/energia/Energia/issue_486/hardware/msp430/cores/msp430/twi_sw.c

They are located in this path: .../hardware/msp430/cores/msp430

curtis63 commented 8 years ago

I am having the same problem as above. Just purchased a brand new Launchpad for G2 from TI. I attached a sensor to it. I am able to successfully communicate with the sensor and get data from it, however, when I run the scanner, I get a device found at all addresses, even though there is only a single sensor.

rei-vilo commented 8 years ago

Which I²C port are you using?

Default I²C port uses pins 9 and 10 now.

rei-vilo commented 8 years ago
msp430g2553
curtis63 commented 8 years ago

Pins 14/15. Aka P1.6/P1.7.

Unable to communicate with my sensor and get valid data however the scanner program does not work. It shows something at every address.

rei-vilo commented 8 years ago

Use default port.

curtis63 commented 8 years ago

Excellent !! It does work when I use Pins 9 and 10. I was using pins 14 and 15.

We have already built a circuit board based on the older spec from 2012. It showed pins 14 and 15 as the SCL/SDA pins. Where would I change the code to switch to pins 14 and 15 instead of the defaults. Surely it's configurable...

StefanSch commented 8 years ago

add a Wire.setModule(0); // 0: indicates the bus as shown in the pin map before the Wire.begin(); // join i2c bus (address optional for master)

curtis63 commented 8 years ago

YAY !!! It works !! I was having grief with it and then pulled my brain out and removed the Jumper that was attaching the LED to P1.6, and all things work correctly now.

Thank you for your assistence !!!

curtis63 commented 8 years ago

So, my Launchpad uses a 20 pin MPS430G2553 chip. On it, P1.6 is pin 14 and P1.7 is pin 15. However, TI makes a 28 pin MPS430G2553 chip. On it, P1.6 is pin 22 and P1.7 is pin 23.
P1.4 is pin 6 and P1.5 is pin 7 on both the 20 pin and the 28 pin MPS430G2553 chip.

Is this going to cause problems using the library with Wire.setModule(0); specified?

StefanSch commented 8 years ago

If you go to the 28 pin device the I2C should work as well as the I2C is on the same port pins. And this is set in the ....\hardware\msp430\variants\launchpad\pins_energia.h file. But you will get a lot of issues on the other pins as the mapping of the pin assigned to the Launchpad and the device will not map. So you may should consider to generate a own pins_energia.h if this is required.

curtis63 commented 8 years ago

Sounds good. My colleague will be testing this on the 28 pin chip tomorrow. I have heard people express concerns about the efficiency of using Energia vs standard C code when programming the MSP430G2553 controller. They are worried about efficiency and about battery power. What is your opinion about the pros and cons of using Energia vs standard C code ?

I LOVE the ease of use of the language and libraries. Nice to have a layer of abstraction over the direct calls that standard C requires.

StefanSch commented 8 years ago

Thanks for the info - it always helps to get the confirmation that a fix is working.

It is a good question to ask about the pros and cons of Energia vs standard c code. I am sure we could have a discussion over a whole evening with some beers. ... and it could also become very philosophic.....

Finally let me try go give you an answer which expresses my opinion: If you need to have a code which is optimized to the final line of code for either execution speed or energy consumption Energia is the wrong tool. If you would like to have a fast prototype or if you not have the time, passion and technical understanding to go down to each configuration bit of a microcontroller energia is a perfect tool. Anything between is up to the user. If you look for efficiency and battery power you can also with Energia build systems which are highly efficient and working for a very long time. But there are some considerations and limitations you may need to be aware of. If you ratio of active time to low power mode time is very high - means you are long time in low power modes, then you will most properly not see a big difference. If you have to wake up very often the it depends if the wake up is mainly handled in an interrupt service routine / handler then it also depends only on your programming skills and on how you have configured the systems. If you wake up very often and always have to go through the loop function then you can might see a higher current consumption in energia. But keep in mind this always depends on how well you know the microcontroller and your skills to optimize your application code for the lowest power consumption base on this device and your use case.

Finally - even as i know the msp430 very well for many, many years i am contributing to this tool as i am convinced from the easy of use, the fast way of building applications and the ecosystem of launchpads and boosterpacks where it is build around. It makes so many things so easy..... just do it .....

curtis63 commented 8 years ago

I really appreciate your help. I’m a 20 year Software Engineer, but have never worked with controllers and firmware before. This is a big learning curve, but Energia makes it MUCH easier..

This may not be the place for technical questions, but I’m trying to get Low Power Mode implemented and saw a couple postings where they use:

disableWatchDog(); and LPM4;

Both of the above statements make my code LOCK up when I attempt to use Serial or delay(); Do you know a good work-around for this? I want to be in low power mode most of the time, and wake up when a sensor interrupts on a port. Where should I look for Energia support functions for this?

spirilis commented 8 years ago

See sleep, sleepSeconds, suspend, and wakeup (the latter is meant for running inside ISRs).

Note you can't use Serial port I/O in low power mode, so you should Serial.flush() (to flush any pending output) before using sleep/sleepSeconds/suspend.