Sign in to follow this  
Followers 0
ninisnanas

CC2530 with MSP430G2553

2 posts in this topic

Hi,

 

I have a CC2530 by Anaren. I have successfully loaded the demo program on my MSP430G2553 from IAR Workbench. Is there any way to convert the code to Energia? I have to move the environment to Energia since the main program is already written in Energia. I have tried to convert the main code in Energia to IAR, but no luck. I have been searching the forums, too. There only exists demo code for CC110L.

 

By the way, if you think that converting from Energia to IAR is way much easier than the other way round, here is my Energia code (this includes 8x8 LED Booster Pack by Olimex):

#include "font.h"

#define LATCH 6
#define CLOCK 7
#define DATA 14
#define DELAYTIME 10
#define PUSH_BUTTON 5

#define TILES 4 // number of tiles
#define CHARNUM 6

int buttonState = 0;

unsigned char image[8*TILES];
const char *str = "Jaggo";

void clearScreen() {
  for (int i = 0; i < 8*TILES; i++) {
    image[i] = 0x00;
  }
}

void sendData(unsigned short data) {
  for (unsigned short i = 0; i < 16; i++) {
      //Serial.println(data, HEX);
      digitalWrite(DATA, data & ((unsigned short)1 << i) ? HIGH : LOW);
      delayMicroseconds(DELAYTIME);
      digitalWrite(CLOCK, HIGH);
      delayMicroseconds(DELAYTIME);
      digitalWrite(CLOCK, LOW);
  }
}

void sendImage(unsigned char *img) {
  unsigned short data;
  for (unsigned int i = 0; i < 8; i++) {
    for (unsigned int n = 0; n < TILES; n++) {
      data = (1 << 8) << i;
      data |= *(img + i + (8*n));
      sendData(data);
    }
  delayMicroseconds(DELAYTIME);
  digitalWrite(LATCH, HIGH);
  delayMicroseconds(DELAYTIME);
  digitalWrite(LATCH, LOW);
  }
}

void setup()
{
  // put your setup code here, to run once:
  //Serial.begin(9600);
  memset(image,0x00,sizeof(image));
  pinMode(CLOCK, OUTPUT); // P1.5
  pinMode(DATA, OUTPUT); // P1.6
  pinMode(LATCH, OUTPUT); // P1.4
  pinMode(PUSH_BUTTON, INPUT_PULLUP); // P1.3
}

void loop()
{
  // put your main code here, to run repeatedly:

  buttonState = digitalRead(PUSH_BUTTON);
  //Serial.println(buttonState, DEC);
 
  if(buttonState == LOW) {
    //image[3] |= 1 << 3;
    int counter = 1;
    int a = 0;
    for (int i = 1; i <= 5*5+5; i++) {
      if (counter % 6 == 0) {
        image[i] = 0x00;
        counter = 1;
        a++;
      }
      else {
        image[i] = FontLookup[lookup(str[a])][(counter - 1)%5];
        counter++;
      }
    }
  }
  sendImage(image);
}

and here is the IAR code:

by the way, I reduced the complexity in the IAR code just to test whether loop for writing data to the LED works (that turns out not working).


#include "io430.h"

#define CLOCK   BIT5
#define DATA    BIT6
#define LATCH   BIT4

unsigned char image[8];
void delay_ms(unsigned int ms);

int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;

  image[0] = 0x7F;
  image[1] = 0x04;
  image[2] = 0x08;
  image[3] = 0x10;
  image[4] = 0x7F;
  image[5] = 0x00;
  image[6] = 0x00;
  image[7] = 0x00;
  
  unsigned short data;
  for (int i = 0; i < 8; i++)
  {
    data = (1 << 8) << i;
    data |= *image;
    for (unsigned short j = 0; j < 16; j++)
    {
      if (data & ((unsigned short) 1 << i))
      {
        P1OUT |= DATA;
      } else
      {
        P1OUT &= ~DATA;
      }
      delay_ms(10);
      P1OUT |= CLOCK;
      delay_ms(10);
      P1OUT &= ~CLOCK;
    }
    delay_ms(10);
    P1OUT |= LATCH;
    delay_ms(10);
    P1OUT &= ~LATCH;
  }
    
  while(1);
}

void delay_ms(unsigned int ms)
{
  while (ms)
  {
    __delay_cycles(16000); //1000 for 1MHz and 16000 for 16MHz
    ms--;
  }
}

Thank you in advance. Your help will be greatly appreciated :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0