Jump to content
Sign in to follow this  
JMLB

Arduino for the launchpad

Recommended Posts

Well, there goes MSPhere :P

I'm unsure. Code still has to be optimized for the Arduino code to fit on the MSP. The 328 has 2Kb RAM and 32Kh flash. How much overhead would the Arduino code have? + we are limited to 1Mhz on the low end and 16 Mhz on the high, compared to 20Mhz on the Arduino.

 

It does simplify work for beginners.

Share this post


Link to post
Share on other sites
@ gatesphere

 

You should work together with the guy who put this code out, or at least communicate with him. It takes the community to make it stronger.

 

Might be good for msphere

Share this post


Link to post
Share on other sites

I created some similar code for some of my projects. I keep meaning to put it together into a useful package and try to do something with the ADC, so we can have AnalogRead(), but keep forgetting.

 

However, I do have some reservations about trying to make things "Arduino plug and play compatible", I see no point in the setup and loop functions as they can be done in main() so easily, is stopping the watchdog that big of a deal? I think every documentation relating to starting out with the MSP430 has said something about it, and as others have mentioned the MSP430G and the Atmega328 are totally different beasts.

 

What would be really nice is to see some helper functions for stuff like the ADC, comparator, flash, interrupts, and low power modes.

Share this post


Link to post
Share on other sites
What would be really nice is to see some helper functions for stuff like the ADC, comparator, flash, interrupts, and low power modes.

 

I've got a couple snippets that are similar to arduino functions. I just assumed this stuff was already out there.

 

Here's what I have for millis and delayMillis:

 

#include "msp430g2231.h"

#define MCLK_FREQUENCY			1000000
#define WDT_DIVIDER				512

const unsigned long WDT_FREQUENCY = MCLK_FREQUENCY / WDT_DIVIDER;
volatile unsigned long wdtCounter = 0;

unsigned long millis(){
return wdtCounter / ((float)WDT_FREQUENCY / 1000);
}

void delayMillis(unsigned long milliseconds){
       // todo: handle rollover
unsigned long wakeTime = wdtCounter + (milliseconds * WDT_FREQUENCY / 1000);
while(wdtCounter < wakeTime);
}

void main(void){
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
WDTCTL = WDTPW + WDTTMSEL + WDTIS1;
IE1 |= WDTIE;
_BIS_SR(GIE);

// toggle pin every second
P1DIR |= BIT0;
while(1){
	P1OUT ^= BIT0;
	delayMillis(1000);
}
}

#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void){
wdtCounter++;
}

 

And here's what I have for analogRead:

 

#include "msp430g2231.h"

#define ANALOG_PIN			4

unsigned int analogRead(){
ADC10CTL0 |= ADC10SC;
while(ADC10CTL1 & ADC10BUSY);
return ADC10MEM;
}

void analogPinSelect(unsigned int pin){
if(pin < 8){
	ADC10CTL0 &= ~ENC;
	ADC10CTL1 = pin << 12;
	ADC10CTL0 = ADC10ON + ENC + ADC10SHT_0;
}
}

void main(void){
unsigned int analogValue;

DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
WDTCTL = WDTPW + WDTHOLD;

// read adc repeatedly
analogPinSelect(ANALOG_PIN);
while(1){
	analogValue = analogRead();
}
}

Share this post


Link to post
Share on other sites
Hmm, I wrote the TiWrap stuff.

 

I'd be up for a collaboration. Especially with the 20 pin MCUs coming out.

 

I'd be willing as well. However, at the moment I'm swamped with classes... If you're interested, PM me. We'll talk.

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.

Sign in to follow this  

×
×
  • Create New...