Jump to content
43oh

st3al

Members
  • Content Count

    6
  • Joined

  • Last visited

Reputation Activity

  1. Like
    st3al reacted to Rickta59 in Energia working with MSP430G2211   
    If you are adventuresome you might grab the latest version from source. I checked in fixes for all this stuff. You don't have to explicitly include the TimerSerial stuff now. The code now creates a Serial instance based on your chip. For g2231/g2542 chips it will pick the TimerSerial, for g2553 it will use HardwareSerial.
     
    It also allows you to change the baud rate with TimerSerial and automatically limits it to 4800 if you are running at 1MHz so that it will work properly.
     
    Source is here:
    https://github.com/energia/Energia/commits/master
     
    Comments and changes I made to fix the issue here:
    https://github.com/energia/Energia/pull/86
     
    check it out
    cd build
    ant clean build run
     
    -rick
  2. Like
    st3al got a reaction from Rickta59 in Energia working with MSP430G2211   
    Thanks Robert!
     
    Here it's the example StateChangeDetection working!
     

    #include TimerSerial mySerial; const int buttonPin = PUSH2; const int ledPin = RED_LED; int buttonPushCounter = 0; int buttonState = 0; int lastButtonState = 0; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); mySerial.begin(); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState != lastButtonState) { if (buttonState == LOW) { buttonPushCounter++; mySerial.println("on"); mySerial.print("number of button pushes: "); mySerial.println(buttonPushCounter); } else { mySerial.println("off"); } } lastButtonState = buttonState; if (buttonPushCounter % 4 == 0) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } if (buttonPushCounter % 3 == 0) { digitalWrite(GREEN_LED, HIGH); } else{ digitalWrite(GREEN_LED, LOW); } }
  3. Like
    st3al reacted to energia in TimerSerial and ADC Problem   
    That output is expected.. Note that you are using TimerSerial.write(). As per API documentation (http://arduino.cc/en/Serial/Write) this will write the bytes binary data to the serial port. If you want something that is readable for us mere humans then use print or println. Also, you seem to want to trigger a read when a character is received from the serial port. Note that you will have to read the buffer otherwise TimerSerail.available() will always return true. Below is a slightly modified version which works for me:
     

    #include TimerSerial mySerial; void setup() { mySerial.begin(); } void loop() { if (mySerial.available()){ mySerial.read(); // do a dummy read to empty the buffer. mySerial.println(analogRead(10)); } delay(1000); }
  4. Like
    st3al reacted to energia in Energia working with MSP430G2211   
    The Serail.xxx API is for Hardware Serial. The G2231 does not have a Hardware Serial peripheral. You can use the timer based TimerSerial. TimerSerial example is in: File->Examples->TimerSerial. Also see https://github.com/energia/Energia/wiki/Know-Issues for a bug fix for TimerSerial on the msp430g2231.
     
    Sorry to have to make you jump through hoops.
     
    Robert
  5. Like
    st3al reacted to Rickta59 in TimerSerial and ADC Problem   
    You could replace TimerSerial::RxIsr with this code:
     

    //Timer A1 interrupt service routine __attribute__((interrupt(TIMERA1_VECTOR))) void TimerSerial::RxIsr(void) { static unsigned char rxBitCnt = 8; static unsigned char rxData = 0; // reading TAIV auto-resets the interrupt flag volatile uint16_t reset_TAIV = TAIV; (void) reset_TAIV; TACCR1 += TICKS_PER_BIT; // Setup next time to sample if (TACCTL1 & CAP) { // Is this the start bit? TACCTL1 &= ~CAP; // Switch capture to compare mode TACCR1 += TICKS_PER_BIT_DIV2; // Sample from the middle of D0 } else { rxData >>= 1; if (TACCTL1 & SCCI) { // Get bit waiting in receive latch rxData |= 0x80; } rxBitCnt--; if (rxBitCnt == 0) { // All bits RXed? store_rxchar(rxData); // Store in ring_buffer rxBitCnt = 8; // Re-load bit counter TACCTL1 |= CAP; // Switch compare to capture mode TACCR1 += TICKS_PER_BIT; // account for the stop bit } } }
     
    The header file for the msp430g2231.h changed between msp430-gcc version 4.5.3 and 4.6.3 breaking the original code. But to be honest unless you run your msp430g2231 chip at 16MHz, you aren't going to be able to send and receive at the same time. There just aren't enough cycles when you add all the code abstraction overhead.
     
    -rick
  6. Like
    st3al reacted to energia in TimerSerial and ADC Problem   
    Also see post: viewtopic.php?f=38&t=2907
×
×
  • Create New...