Hi
I need to communicate with 2 different devices using different baud rates over 
UART0. So I wrote a simple test program to begin with where I program one 
Tmote as a sender and one as a receiver and used Leds to indicate whether or 
not send, receive returned SUCCESS and whether the rcvd byte matched the sent 
byte. To avoid possibility of config errors, I always return 
msp430_uart_default config to UartConfigure and change the baud rate and 
modulation settings for the default config(UBR_1MHZ_xxx and 
UMCTL_1MHZ_xxx) directly in msp430usart.h for each run. 
The logic is as follows:
Sender :
1. At boot, start a 1s periodic timer
Variant 2. Timer.fired -> request resource -> granted -> send 1 byte -> 
sendDone -> release 
Variant 2a. Timer.fired -> if (immediateRequest == SUCCESS) -> send 1 byte -> 
sendDone -> release
Receive
1. At boot, request resource -> granted -> enable Receive interrupt
2. receivedByte -> check byte and toggle LED
Strangely, program 2 (request and release every second) works at 115200bps but 
not at 57600, 19200 or 9600 
But program 2a, which is the same logic except that I use immediateRequest() 
followed by send works at 115200 and 57600 but not at 19200 or 9600
Finally, I tried a 3rd variant in which the sender requests the resource at 
boot, and never releases it and directly posts the send whenever the timer 
fires. This variant works for all of the baud rates listed above. 
Again, to change the baud rates, I directly modify the 2 parameter values 
(UBR_1MHZ_xxx and UMCTL_1MHZ_xxx) in msp430_uart-default_config in 
msp430usart.h and always return msp430_default_config to UartConfigure. Btw, I 
also tried passing my own config set and that didn't work either, so for 
debugging, I just return the default config and change its definition before 
compiling each time. 
Please let me know if I am doing something wrong here. I am pasting the program 
text below (both Resource and UartStream are wired to a new instance of 
Msp430Uart0C() )
#include "msp430usart.h"
module TestUartC{
provides interface Msp430UartConfigure;
uses { interface Boot; interface Timer<TMilli> as MilliTimer; interface 
Resource; interface UartStream; interface Leds;} 
}
implementation {
event void Boot.booted()
{
if (TOS_NODE_ID == 1){      //sender is prog with id 1 - start timer
        call MilliTimer.startPeriodic(1024);
        //call Resource.request(); - for variant 3; request and never release
}
else if (TOS_NODE_ID == 2) // rcvr is prog with id 2- req resource
       call Resource.request();
}
async command msp430_uart_union_config_t* Msp430UartConfigure.getConfig() {
    call Leds.led2Toggle();
    return &msp430_uart_default_config; // also tried to populate my own union 
and return it 
}
 
void task sendTask(){
    uint8_t data=0x63; 
    if ((call UartStream.send(&data,1)) == SUCCESS)
           call Leds.led0Toggle();    // this always toggles at 1Hz
}
event void Resource.granted(){
    if (TOS_NODE_ID == 1){ //sender - send 1 byte
        post sendTask();
    }
    else if (TOS_NODE_ID == 2)
        call UartStream.enableReceiveInterrupt(); //rcvr - enable receive
}
event void MilliTimer.fired(){  //only fires in sender - req for sending
    call Resource.request();
    // if (call Resource.immediateRequest() == SUCCESS) post sendTask(); // 
variant 2a 
}
void task release(){
    call Resource.release();
}
async event void UartStream.sendDone(uint8_t* buf, uint16_t len, error_t error) 
{
    if (error == SUCCESS) call Leds.led1Toggle();    //always toggles at 1Hz, 
indicating send success
    post release(); //release after send
}
async event void UartStream.receivedByte( uint8_t test ) {
    call Leds.led0Toggle();        //both leds only toggle under the settings 
described above
    if (test==0x63) 
        call Leds.led1Toggle();
}
async event void UartStream.receiveDone( uint8_t* buf, uint16_t len, error_t 
error ){}
}


      
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to