Problem


When trying to compile code for the MSP430 Experimental board (specifically the MSP-EXP430FR5739) in Energia version 0101E0017 the following error stream is presented:

C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c: In function 'i2c_sw_init':
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:43:16: error: 'TWISDA1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:43:16: note: each undeclared identifier is reported only once for each function it appears in
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:44:16: error: 'TWISCL1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c: In function 'i2c_sw_start':
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:84:11: error: 'TWISDA1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:86:11: error: 'TWISCL1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c: In function 'i2c_sw_txByte':
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:99:15: error: 'TWISDA1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:103:13: error: 'TWISCL1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c: In function 'i2c_sw_ack':
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:122:12: error: 'TWISCL1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c: In function 'i2c_sw_rxByte':
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:132:12: error: 'TWISDA1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:136:15: error: 'TWISCL1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c: In function 'i2c_sw_stop':
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:157:11: error: 'TWISDA1' undeclared (first use in this function)
C:\Program Files (x86)\Energia\hardware\msp430\cores\msp430\twi_sw.c:159:11: error: 'TWISCL1' undeclared (first use in this function)

The issues occurs because the I2C SW library loads but isn’t included explicitly so the sketch won’t load (yay c)


Resolution


The fix is documented here and is available for people who clone their Energia from Github instead of using the installation binary.

You have two options:

  1. Clone/Update from the GitHub repo
  2. Make the changes yourself!

Your choice…


Option 1 - Clone/Update


Ensure you have git installed and clone the repo to a desired location on your hard drive

git clone --recursive https://github.com/energia/Energia.git

If you already have a clone of Energia then:

git submodule update --init --recursive
git submodule sync
cd emt
git pull
cd ..

Option 2 - Update yourself


Navigate to the following subdirectory of the Energia folder and open twi_sw.c

Energia\hardware\msp430\cores\msp430\twi_sw.c

On line 26 you should see your #include "twi_sw.h". Just below that add the following line:

#if DEFAULT_I2C == -1 /* indicates SW I2C on pseudo module 1 */

Line Change 1

On the last line in the file (just after the last bracket) add your endif statement

#endif // #if DEFAULT_I2C = -1 /* indicates SW I2C on pseudo module 1 */

Line Change 2


Results


After making the changes above you should be able to push your sketch over to your MSP430 without any issues