Jump to content

File Changes to Support MSP430G2452 and SPI

Recommended Posts

I downloaded Energia 1.6.10e18

I am programming an msp430g2452

I am using LanchPad MSP-EXP430G2 to program my part (on a custom board via spi-by-wire)

I am running Energia on Windows 7

I ran update on Energia MSP430 boards via Boards Manager to version 1.0.2

When compiling I get the following errors:


Build options changed, rebuilding all
C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\libraries\SPI\utility\usi_spi.cpp: In function 'void spi_transmit16(uint16_t)':

C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\libraries\SPI\utility\usi_spi.cpp:135:20: error: 'spi_tx' was not declared in this scope

C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\libraries\SPI\utility\usi_spi.cpp: In function 'void spi_transmit(void*, uint16_t)':

C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\libraries\SPI\utility\usi_spi.cpp:144:14: error: 'spi_tx' was not declared in this scope

exit status 1
Error compiling for board MSP-EXP430G2 w/ MSP430G2452.

In usi_spi.cpp I had to change a couple of instances of spi_tx to spi_send (fixed code below):

void spi_transmit16(const uint16_t data)
	spi_send(data & 0xFF);
	spi_send((data>>8) & 0xFF);

void spi_transmit(void *buf, uint16_t count)
    uint8_t *p = (uint8_t *)buf;
	if (count == 0) return;


Code then compiles, but doesn't run properly.  The warnings are:


C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\cores\msp430\atof.c: In function 'atof':

C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\cores\msp430\atof.c:71:9: warning: floating constant exceeds range of 'double' [-Woverflow]

C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\cores\msp430\wiring.c: In function 'initClocks':

C:\Users\WirickD\AppData\Local\Energia15\packages\energia\hardware\msp430\1.0.2\cores\msp430\wiring.c:273:10: warning: #warning No Suitable Frequency found! [-Wcpp]

Sketch uses 2,662 bytes (32%) of program storage space. Maximum is 8,192 bytes.
Global variables use 74 bytes (28%) of dynamic memory, leaving 182 bytes for local variables. Maximum is 256 bytes.

To fix the clock problem, in msp430g2452.h I had to add a section defining the TLV data (added at line 760):

* Offest Indexed TLV Data in Mem

/* TLV Calibration Data Structure, Datasheet Table 9 */
#define TAG_DCO_30             (0x01)    /* Tag for DCO30  Calibration Data */
#define TAG_ADC10_1            (0x10)    /* Tag for ADC10_1 Calibration Data */
#define TAG_EMPTY              (0xFE)    /* Tag for Empty Data Field in Calibration Data */

#ifndef __DisableCalData
#define TLV_CHECKSUM_         0x10C0    /* TLV CHECK SUM */
#define TLV_DCO_30_TAG_       0x10F6    /* TLV TAG_DCO30 TAG */
const_sfrb(TLV_DCO_30_TAG, TLV_DCO_30_TAG_);
#define TLV_DCO_30_LEN_       0x10F7    /* TLV TAG_DCO30 LEN */
const_sfrb(TLV_DCO_30_LEN, TLV_DCO_30_LEN_);
#define TLV_ADC10_1_TAG_      0x10DA    /* TLV ADC10_1 TAG */
const_sfrb(TLV_ADC10_1_TAG, TLV_ADC10_1_TAG_);
#define TLV_ADC10_1_LEN_      0x10DB    /* TLV ADC10_1 LEN */
const_sfrb(TLV_ADC10_1_LEN, TLV_ADC10_1_LEN_);

* ADC Calibration Data Mem Offsets (offset from 0x10DA)

/* Datasheet Table 10 */

#define CAL_ADC_25T85          (0x0010)  /* Index for 2.5V/85Deg Cal. Value */
#define CAL_ADC_25T30          (0x000E)  /* Index for 2.5V/30Deg Cal. Value */
#define CAL_ADC_25VREF_FACTOR  (0x000C)  /* Index for 2.5V Ref. Factor */
#define CAL_ADC_15T85          (0x000A)  /* Index for 1.5V/85Deg Cal. Value */
#define CAL_ADC_15T30          (0x0008)  /* Index for 1.5V/30Deg Cal. Value */
#define CAL_ADC_15VREF_FACTOR  (0x0006)  /* Index for ADC 1.5V Ref. Factor */
#define CAL_ADC_OFFSET         (0x0004)  /* Index for ADC Offset */
#define CAL_ADC_GAIN_FACTOR    (0x0002)  /* Index for ADC Gain Factor */

* DCO Calibration Data Mem Offsets (offset from 0x10F6), Datasheet Table 10

/* Datasheet Table 10 */

#define CAL_DCO_16MHZ          (0x0002)  /* Index for DCOCTL  Calibration Data for 16MHz */
#define CAL_BC1_16MHZ          (0x0003)  /* Index for BCSCTL1 Calibration Data for 16MHz */
#define CAL_DCO_12MHZ          (0x0004)  /* Index for DCOCTL  Calibration Data for 12MHz */
#define CAL_BC1_12MHZ          (0x0005)  /* Index for BCSCTL1 Calibration Data for 12MHz */
#define CAL_DCO_8MHZ           (0x0006)  /* Index for DCOCTL  Calibration Data for 8MHz */
#define CAL_BC1_8MHZ           (0x0007)  /* Index for BCSCTL1 Calibration Data for 8MHz */
#define CAL_DCO_1MHZ           (0x0008)  /* Index for DCOCTL  Calibration Data for 1MHz */
#define CAL_BC1_1MHZ           (0x0009)  /* Index for BCSCTL1 Calibration Data for 1MHz */


Now code compiles and runs properly on the processor.  I have not tested out SPI data yet, so I'm not 100% that it works.


Just thought people might like to know, thanks!






Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...