Jump to content
inspect

Help me port energia to msp430f2274

Recommended Posts

UPDATE: i accidently wrote msp430g2274 instead of msp430f2274 in the title of thread.I tried to change title by editing it using full editor but i can't.It gives me some error that thread key is not matched and it signs out.

Hey guys,
 
I  first changed boards.txt file under /hardware/msp430 by adding following code

lpmsp430fr5739.name=msp430f2274
lpmsp430fr5739.upload.protocol=rf2500
lpmsp430fr5739.upload.maximum_size=32768
lpmsp430fr5739.build.mcu=msp430f2274
lpmsp430fr5739.build.f_cpu=16000000L
lpmsp430fr5739.build.core=msp430
lpmsp430fr5739.build.variant=msp430f2274

and also added "pins_energia_.h" which is simply a copy of launchpad's "pins_energia.h" in folder /hardware/msp430/variants/msp430f2274.

for now i've not just added pin description of msp430f2274.i am right now just testing whether the code of g2553 can compile or not.when i compile the code it gives me follo\wing error:

\energia-0101E0009\hardware\msp430\cores\msp430\twi.c: In function 'twi_init':
\energia-0101E0009\hardware\msp430\cores\msp430\twi.c:122:5: error: 'P1SEL2' undeclared (first use in this function)
\energia-0101E0009\hardware\msp430\cores\msp430\twi.c:122:5: note: each undeclared identifier is reported only once for each function it appears in

But when i change this line in boards.txt:

lpmsp430fr5739.build.mcu=msp430f2274

to

lpmsp430fr5739.build.mcu=msp430g2553

It successfully compiles.So plz tell me wht m i doing wrong here.?

Share this post


Link to post
Share on other sites

Made this yesterday; seems to work ok.

 

energia/hardware/msp430/variants/rf2500t/pins_energia.h

 

EDIT: 12-20-13 Updated pin connections. Also put this on github with pull request.

/*
  ************************************************************************
  *    pins_energia.h
  *
  *    Energia core files for MSP430
  *        Copyright (c) 2012 Robert Wessels. All right reserved.
  *
  *     Contribution: Rei VILO
  *
  ***********************************************************************
  Derived from:
  pins_arduino.h - Pin definition functions for Arduino
  Part of Arduino - http://www.arduino.cc/

  Copyright (c) 2007 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
*/

#ifndef Pins_Energia_h
#define Pins_Energia_h
#ifndef BV
#define BV(x) (1 << (x))
#endif

#if defined(__MSP430_HAS_USCI__)

static const uint8_t SS      = 9;  /* P3.0 */
static const uint8_t SCK     = 11;  /* P3.3 */
static const uint8_t MOSI    = 10;  /* P3.1 */
static const uint8_t MISO    = 8;  /* P3.2 */

static const uint8_t TWISDA  = 10;  /* P3.1 */
static const uint8_t TWISCL  = 8;  /* P3.2 */

static const uint8_t DEBUG_UARTRXD = 20;  /* Receive  Data (RXD) at P3.5 */
static const uint8_t DEBUG_UARTTXD = 19;  /* Transmit Data (TXD) at P3.4 */

#define TWISDA_SET_MODE (PORT_SELECTION0)
#define TWISCL_SET_MODE (PORT_SELECTION0)
#define DEBUG_UARTRXD_SET_MODE (PORT_SELECTION0 | (PORT_SELECTION1) | INPUT)
#define DEBUG_UARTTXD_SET_MODE (PORT_SELECTION0 | (PORT_SELECTION1) | OUTPUT)
#define SPISCK_SET_MODE (PORT_SELECTION0)
#define SPIMOSI_SET_MODE (PORT_SELECTION0)
#define SPIMISO_SET_MODE (PORT_SELECTION0)
#endif

#define DEBUG_UART_MODULE_OFFSET 0x00

static const uint8_t A0  = 0;
static const uint8_t A1  = 1;
static const uint8_t A2  = 2;
static const uint8_t A3  = 3;
static const uint8_t A4  = 4;
static const uint8_t A5  = 5;
static const uint8_t A6  = 6;
static const uint8_t A7  = 7;
static const uint8_t A10 = 10; // special. This is the internal temp sensor
static const uint8_t A11  = 11;
static const uint8_t A12  = 12;
static const uint8_t A13  = 13;
static const uint8_t A14  = 14;
static const uint8_t A15  = 15;

/*
F2274 RF2500T pin mapping

                                debug uart up

                               +--\/--+
                          VCC  |1   18| GND
                     (A1) P2.1 |2   17| P2.0 (A0)
                (TA1, A3) P2.3 |3   16| P2.2 (TA1, A2)
               (TB0, A12) P4.3 |4   15| P2.4 (TA2, A4)
               (TB2, A14) P4.5 |5   14| P4.4 (TB1, A13)
                           GND |6   13| P4.6 (A15)
             (XOUT, GDO2) P2.7 |7   12| P2.6 (XIN, GDO0)
                (UCB0CLK) P3.3 |8   11| P3.2 (UCB0SOMI)
               (UCB0SIMO) P3.1 |9   10| P3.0 (UCB0STE)
                               +------+

*/

/* Pin names based on the silkscreen */

/* PIN1 = VCC */
static const uint8_t P2_1 = 2;
static const uint8_t P2_3 = 3;
static const uint8_t P4_3 = 4;
static const uint8_t P4_5 = 5;
/* PIN6 = GND */
static const uint8_t P2_7 = 7;
static const uint8_t P3_3 = 8;
static const uint8_t P3_1 = 9;
static const uint8_t P3_0 = 10;
static const uint8_t P3_2 = 11;
static const uint8_t P2_6 = 12;
static const uint8_t P4_6 = 13;
static const uint8_t P4_4 = 14;
static const uint8_t P2_4 = 15;
static const uint8_t P2_2 = 16;
static const uint8_t P2_0 = 17;
/* PIN18 = GND */

/* Extra pins not on the header + temp sensor */
static const uint8_t P3_4 = 19;        //TXD0
static const uint8_t P3_5 = 20;        //RXD0

static const uint8_t P1_0 = 21;        //grn
static const uint8_t P1_1 = 22;        //red
static const uint8_t P1_2 = 23;        //button

static const uint8_t RED = 21;        //P1.0
static const uint8_t RED_LED = 21;
static const uint8_t GREEN = 22;    //P1.1
static const uint8_t GREEN_LED = 22;
static const uint8_t BUTTON = 23;    //P1.2

static const uint8_t TEMPSENSOR = 10;    //internal A10

/* Onboard CC2500 */
static const uint8_t GDO0 = 12;        //P2.6
static const uint8_t GDO2 = 7;        //P2.7

#ifdef ARDUINO_MAIN

const uint16_t port_to_input[] = {
    NOT_A_PORT,
    (uint16_t) &P1IN,
    (uint16_t) &P2IN,
#ifdef __MSP430_HAS_PORT3_R__
    (uint16_t) &P3IN,
#endif
#ifdef __MSP430_HAS_PORT4_R__
    (uint16_t) &P4IN,
#endif

};

const uint16_t port_to_output[] = {
    NOT_A_PORT,
    (uint16_t) &P1OUT,
    (uint16_t) &P2OUT,
#ifdef __MSP430_HAS_PORT3_R__
    (uint16_t) &P3OUT,
#endif
#ifdef __MSP430_HAS_PORT4_R__
    (uint16_t) &P4OUT,
#endif

};

const uint16_t port_to_dir[] = {
    NOT_A_PORT,
    (uint16_t) &P1DIR,
    (uint16_t) &P2DIR,
#ifdef __MSP430_HAS_PORT3_R__
    (uint16_t) &P3DIR,
#endif
#ifdef __MSP430_HAS_PORT4_R__
    (uint16_t) &P4DIR,
#endif

};

const uint16_t port_to_ren[] = {
    NOT_A_PORT,
    (uint16_t) &P1REN,
    (uint16_t) &P2REN,
#ifdef __MSP430_HAS_PORT3_R__
    (uint16_t) &P3REN,
#endif
#ifdef __MSP430_HAS_PORT4_R__
    (uint16_t) &P4REN,
#endif

};

const uint16_t port_to_sel0[] = {  /* put this PxSEL register under the group of PxSEL0 */
    NOT_A_PORT,
    (uint16_t) &P1SEL,
    (uint16_t) &P2SEL,
#ifdef __MSP430_HAS_PORT3_R__
    (uint16_t) &P3SEL,
#endif
#ifdef __MSP430_HAS_PORT4_R__
    (uint16_t) &P4SEL,
#endif

};


const uint8_t digital_pin_to_timer[] = {
    NOT_ON_TIMER, /*  dummy */
    NOT_ON_TIMER, /*  1 - VCC */
    NOT_ON_TIMER, /*  2 - P2.1 */
    T0A1,         /*  3 - P2.3 */
    T0B0,         /*  4 - P4.3 */
    T0B2,         /*  5 - P4.5 */
    NOT_ON_TIMER, /*  6 - GND */
    NOT_ON_TIMER, /*  7 - P2.7 */
    NOT_ON_TIMER, /*  8 - P3.3 */
    NOT_ON_TIMER, /*  9 - P3.1 */
    NOT_ON_TIMER, /* 10 - P3.0 */
    NOT_ON_TIMER, /* 11 - P3.2 */
    NOT_ON_TIMER, /* 12 - P2.6 */
    NOT_ON_TIMER, /* 13 - P4.6 */
    T0B1,         /* 14 - P4.4 */
    T0A2,         /* 15 - P2.4 */
    T0A0,         /* 16 - P2.2 */
    NOT_ON_TIMER, /* 17 - P2.0 */
    NOT_ON_TIMER, /* 18 - GND */
    NOT_ON_TIMER, /* 19 - P3.4 */
    NOT_ON_TIMER, /* 20 - P3.5 */
    NOT_ON_TIMER, /* 21 - P1.0 */
    T0A0,         /* 22 - P1.1 */
    T0A1          /* 23 - P1.2 */

};

const uint8_t digital_pin_to_port[] = {
    NOT_A_PIN, /* dummy */
    NOT_A_PIN, /* 1 */
    P2,        /* 2 */
    P2,        /* 3 */
    P4,        /* 4 */
    P4,        /* 5 */
    NOT_A_PIN,        /* 6 */
    P2,        /* 7 */
    P3,        /* 8 */
    P3,        /* 9 */
    P3,        /* 10 */
    P3,        /* 11 */
    P2,        /* 12 */
    P4,         /* 13 */
    P4,        /* 14 */
    P2,        /* 15 */
    P2,        /* 16 */
    P2,        /* 17 */
    NOT_A_PIN, /* 18 */
    P3,           /* 19 */
    P3,           /* 20 */
    P1,           /* 21 */
    P1,           /* 22 */
    P1           /* 23 */
};

const uint8_t digital_pin_to_bit_mask[] = {
    NOT_A_PIN, /* 0,  pin count starts at 1 */
    NOT_A_PIN, /* 1 */
    BV(1),     /* 2 */
    BV(3),     /* 3 */
    BV(3),     /* 4 */
    BV(5),     /* 5 */
    NOT_A_PIN,     /* 6 */
    BV(5),     /* 7 */
    BV(3),     /* 8 */
    BV(1),     /* 9 */
    BV(0),     /* 10 */
    BV(2),     /* 11 */
    BV(6),     /* 12 */
    BV(6),         /* 13 */
    BV(4),     /* 14 */
    BV(4),     /* 15 */
    BV(2),       /* 16 */
    BV(0),     /* 17 */
    NOT_A_PIN, /* 18 */
    BV(4),     /* 19 */
    BV(5),       /* 20 */
    BV(0),       /* 21 */
    BV(1),       /* 22 */
    BV(2),     /* 23 */

};
#endif // #ifdef ARDUINO_MAIN
#endif // #ifndef Pins_Energia_h



Share this post


Link to post
Share on other sites

Dooh, should have searched before venturing out and doing it myself :)

 

I did the pin numbering following silkscreen / schematic, i.e. alternating between left and right. Also started extras at pin 20.

F22x4 RF2550T pin mapping
                               +--\/--+
                          GND  |1    2| VCC
                     (A0) P2.0 |3    4| P2.1 (A1)
                     (A2) P2.2 |5    6| P2.3 (A3)
                     (A4) P2.4 |7    8| P4.3 (A12)
                    (A13) P4.4 |9   10| P4.5 (A14)
                    (A15) P4.6 |11  12| GND
            (CC2500 GDO0) P2.6 |13  14| P2.7 (CC2500 GDO2)
     (UCB0SCL) (UCB0SOMI) P3.2 |15  16| P3.3 (UCB0SCK)
                     (SS) P3.0 |17  18| P3.1 (UCB0SIMO) (UCB0SDA)
                               +------+
                                 ----+
                                   20| P1.0 (LED1 - RED)
                                   21| P1.1 (LED2 - GREEN)
                                   22| P1.2 (PUSH1)
                                   24| P3.4 (UCA0TXD -> ezFET -> Serial)
                                   25| P3.5 (UCA0RXD -> ezFET -> Serial)
                                 ----+

I called the folder under variants "ez430-rf2500t", i.e. the full model number of the F2274 kit.

 

Only checked Serial, blink, button-press and analog write examples. With analog write my green LED only blinks but does not fade. Any ideas what could cause this?

boards.txt

pins_energia.h

Share this post


Link to post
Share on other sites

@@gwdeveloper did you get SPI with the CC2500 working?

 

I can send commands, but SPI.transfer always returns 0.

 

Attached my pins_energia.h (Energia 0012)

 

Test program:

#include <SPI.h>

void setup()
{
  // configure CS and turn it off
  pinMode(17,OUTPUT);
  digitalWrite(17,HIGH);

  // setup SPI, MSB first, slow and steady
  SPI.begin();
  SPI.setBitOrder(1);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  Serial.begin(9600);
}

void loop()
{
  // enable CS
  digitalWrite(17,LOW);

  // wait for device, MISO is high when busy
  while (digitalRead(15) == HIGH);

  // send NOP, should return chip status
  uint8_t result = SPI.transfer(0x3d);

  // disable CS
  digitalWrite(17,HIGH);

  Serial.print("SPI: ");
  Serial.println(result);

  delay(1000);
}

SPI trace, as you can see, there's a response on MISO:

post-9974-0-33709000-1395985390_thumb.png

 

And schematic, MISO is pin P3.2, which is on header pin 15.

post-9974-0-69820100-1395986009_thumb.png

 

Any ideas what could be wrong here? I double and triple checked pins_energia.h but can't see an error.

 

pins_energia.h

Share this post


Link to post
Share on other sites

Know what.. talking to myself here :) .. Energia reconfigures PSEL inside of digitalRead, which screws up the SPI configuration :wacko: When I uncomment PSEL section inside digitalRead everything works as expected.

 

Is that the Arduino way? If not, IMO that should be fixed in Energia.

Share this post


Link to post
Share on other sites

At some point (possibly now) the following might be useful to you:

/* Ensure CC2500 CSn is held high to avoid issues with use of I2C. */
#define BSP430_PLATFORM_STANDARD_INITIALIZE_EPILOGUE do {       \
    P3DIR |= BIT0;                                              \
    P3OUT |= BIT0;                                              \
  } while (0)
I use this in platform initialization on the RF2500T when I don't intend to use the on-board CC2500. Without it, I2C does not behave as desired.

Share this post


Link to post
Share on other sites

Know what.. talking to myself here :) .. Energia reconfigures PSEL inside of digitalRead, which screws up the SPI configuration :wacko: When I uncomment PSEL section inside digitalRead everything works as expected.

 

Is that the Arduino way? If not, IMO that should be fixed in Energia.

I'm not sure Arduino (AVR chips) have the PxSEL feature, or what they do in those instances.  I'm inclined to say the PxSEL clear in digitalRead() is a superfluous thing to have though, and should be removed from Energia's core.  Looking at the Port Schematics on the G2553 at least, for the USCI_B ports (P1.5-P1.7), PxIN receives the value of the schmitt trigger which is connected in parallel to the PxSEL-enabled module, so reading PxIN while a PxSEL bit is set should still be OK and accurate.

 

@@energia any comment?  Seems like a small change :)

Talking about removing the PxSEL part from here (hardware/msp430/cores/msp430/wiring_digital.c):

int digitalRead(uint8_t pin)
{
        uint8_t bit = digitalPinToBitMask(pin);
        uint8_t port = digitalPinToPort(pin);
        volatile uint8_t *sel;

        if (port == NOT_A_PORT) return LOW;

// remove all this crud--
        /*
         * Clear bit in PxSEL register to select GPIO function. Other functions like analogWrite(...) 
         * will set this bit so need to clear it.
         */
#if (defined(P1SEL_) || defined(P1SEL))
        sel = portSel0Register(port);   /* get the port function select register address */
        *sel &= ~bit;                   /* clear bit in pin function select register */
#endif
#if (defined(P1SEL2_) || defined(P1SEL2))
        sel = portSel2Register(port);   /* get the port function select register address */
        *sel &= ~bit;                   /* clear bit in pin function select register */
#endif
#if (defined(P1SEL0_) || defined(P1SEL0))
        sel = portSel0Register(port);   /* get the port function select register address */
        *sel &= ~bit;                   /* clear bit in pin function select register */
#endif
#if (defined(P1SEL1_) || defined(P1SEL1))
        sel = portSel1Register(port);   /* get the port function select register address */
        *sel &= ~bit;                   /* clear bit in pin function select register */
#endif
// end of crud to be removed

        if (*portInputRegister(port) & bit) return HIGH;
        return LOW;
}

I definitely think that code should be in digitalWrite(), just not digitalRead().

Share this post


Link to post
Share on other sites

@@gwdeveloper Yep, got SPI working and the radio now talks to me. Next up adapting one of the CC2500 examples for Arduino.

 

@@pabigot Thanks for the warning!

 

Regarding the PSEL issue: It looks like it was introduced with support for the F5529 port mapping:

https://github.com/energia/Energia/blame/master/hardware/msp430/cores/msp430/wiring_digital.c#L181

If nobody objects, I will include the fix in the R2500T pull-request.

Share this post


Link to post
Share on other sites

@chicken  Perfect; that was the library I previously tried but no luck.  You've solved the issue with the PxSEL.

 

I'm going to download and try your pins_energia.h.  Your pin numbering scheme was different than mine; I followed the same protocol as other boards with starting at 1 going counter clockwise to 18.  Also a few extra defines were added for my own convenience.

 

Did you get Fade working with your pins file?  I bet we could wrap up this variant pretty quickly.

Share this post


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.

Guest
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...