Hi Karlis,
sorry but I can't help you at all. I only try to use the UART interface, and
the only way that I find to use the RADIO and the PINS too is shown in the
next code that I paste in trail of the post.
I think that use the I2C bus should be very similar to the uart utilization.
You only need to change the component Msp430I2CC() instead of
Msp430Uart0C(), change the configuration variable and the method to send the
data (that in the I2C standard need some other information like for example
the ADDRESS).

I have some trouble with the UART interface...in fact I need a IDLE HIGH
state to communicate with my external RGB device...but when the UART release
to the arbiter the USART resource the UART0TX pin became IDLE LOW (that is
not a TTL standard). Moreover If I send (for example) 3 byte with the "call
UartStream.send" the mote sends only 2 bytes (always one less) ...and I'm
not able to find the mistake....
Can someone help us?!
Have someone olready use the EXTERNAL PINS??
thanks to all.



****************************************************************************************
THE CODE IS A MODIFICATION OF THE TEST BLINK APPLICATION  (sorry for the
nomenclature)


The application send every second a message through the radio (toggle the
JELLOW led) , and every 0,5 sec 3 bytes via UART (toggle the RED led).

//************************* BlinkToRadioAppC.nc

#include <Timer.h>
 #include "BlinkToRadio.h"
#include <msp430usart.h>

 configuration BlinkToRadioAppC {
 }
 implementation {
   components MainC;
   components LedsC;
   components BlinkToRadioC as App;
   components new TimerMilliC() as Timer0;
   components new TimerMilliC() as Timer1;
   components CC2420TimeSyncMessageC;
       components new Msp430Uart0C() as U;

    components RandomC;


     App.Random->RandomC;
    App.RandomInit->RandomC;

   App.Boot -> MainC;
   App.Leds -> LedsC;
   App.Timer0 -> Timer0;
   App.Timer1 -> Timer1;

    App.Receive-> CC2420TimeSyncMessageC.Receive[AM_BLINKTORADIOMSG];
     App.AMControl->CC2420TimeSyncMessageC.SplitControl;
     App.Packet->CC2420TimeSyncMessageC.Packet;
      App.AMPacket->CC2420TimeSyncMessageC.AMPacket;
    App.TimeSyncPacket -> CC2420TimeSyncMessageC.TimeSyncPacket32khz;
      App.TimeSyncAMSend ->
CC2420TimeSyncMessageC.TimeSyncAMSend32khz[AM_BLINKTORADIOMSG];






    App.Resource1->U;
    App.UartStream->U;
    App.Msp430UartConfigure<-U;

}


//************************* BlinkToRadioC.nc


 #include <Timer.h>
 #include "BlinkToRadio.h"



 module BlinkToRadioC {
   uses interface Boot;
   uses interface Leds;
   uses interface Timer<TMilli> as Timer0;
   uses interface Timer<TMilli> as Timer1;
   uses interface Packet;
   uses interface AMPacket;
   uses interface TimeSyncPacket<T32khz,uint32_t>;
   uses interface TimeSyncAMSend<T32khz,uint32_t>;
   uses interface SplitControl as AMControl;
   uses interface Receive;
    uses interface Resource as Resource1;

    uses interface UartStream;

    uses interface Init as RandomInit;
    uses interface Random;

    provides {
    interface Msp430UartConfigure;
     }

 }
 implementation {
   uint8_t byte1= 0;
   uint8_t byte2= 0;
   uint8_t byte3= 0;

   bool busy = FALSE;
   message_t pkt;
   BlinkToRadioMsg* outPtr;

    uint8_t buffer [3];
    uint8_t* ptr;
     uint8_t i;
     uint32_t rand;
     uint32_t rand2;


//#ifdef PROPERTIES
//Here I can see a lot of properties!!
     msp430_uart_union_config_t msp430_uart_19200_config = {
    {
      ubr : UBR_1MHZ_19200,
      umctl : UMCTL_1MHZ_19200,
      ssel : 0x01,
      pena : 0,
      pev : 0,
      spb : 0,
      clen : 1,
      listen : 0,
      mm : 0,
      ckpl : 0,
      urxse : 0,
      urxeie : 1,
      urxwie : 0,
      utxe : 1,
      urxe : 1
    }
  };


  async command msp430_uart_union_config_t* Msp430UartConfigure.getConfig()
  {
    return &msp430_uart_19200_config;
  }


   event void Boot.booted() {

     call AMControl.start();
    call RandomInit.init();
     byte1=(uint8_t)23;
     byte2=(uint8_t)129;
     byte3=(uint8_t)55;
     ptr=&buffer[0];
     call Timer1.startOneShot(500);
     call Timer0.startPeriodic(1000);

   }

   event void AMControl.startDone(error_t err) {
       if (err == SUCCESS) {

         outPtr = (BlinkToRadioMsg*) (call Packet.getPayload(&pkt, 0));
     }
     else {
         call AMControl.start();}
   }


task void sendRadioMsg(){

        if (!busy){

        atomic{ //call TimeSyncAMSend.send(am_addr_t addr, message_t *msg,
uint8_t len, size_type event_time)
            if (call TimeSyncAMSend.send(AM_BROADCAST_ADDR, &pkt,
sizeof(BlinkToRadioMsg), 300) == SUCCESS)
             {
                busy = TRUE;
                 call Leds.led1Toggle();

                 }else {

                     call Leds.led2On();}
        }
        }else{

            call TimeSyncAMSend.cancel(&pkt);
            //post sendRadioMsg();
            }
    }



   event void AMControl.stopDone(error_t err){
   }

     event void Timer0.fired(){
         atomic{
               byte1=((byte1+1)%255);
               byte2=((byte2+1)%255);
               byte3=((byte3+1)%255);
           }
          outPtr->nodeId = TOS_NODE_ID;
         outPtr->byte1 = byte1;
         outPtr->byte2 = byte2;
         outPtr->byte3 = byte3;

         post sendRadioMsg();

     }

   event void Timer1.fired() {
           call Resource1.request();

   }

   event void TimeSyncAMSend.sendDone(message_t* msg, error_t error){
           busy=FALSE;
           if (error == FAIL){
               call Leds.led2On();
               //printf("\nSpedizione via radio CON ERRORE ma send done
lanciato!!\n\n");
                 //printfflush();
               }
           else if (&pkt == msg) {
               //printf("\nSpedizione via radio TERMINATA!!\n\n");
                 //printfflush();
           }
   }

   event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
len){
                  return msg;
   }



    event void Resource1.granted(){
         buffer[0]=byte1;
         buffer[1]=byte2;
         buffer[2]=byte3;
         atomic{
             if (call UartStream.send(ptr, 3)== SUCCESS){
                 call Leds.led0Toggle();

             }else {
                 call Leds.led2On();
             }
                  call Timer1.startOneShot(500);
         }
     }


    async event void UartStream.receiveDone(uint8_t *buf, uint16_t len,
error_t error){
        // TODO Auto-generated method stub
    }

    async event void UartStream.receivedByte(uint8_t byte){
        // TODO Auto-generated method stub
    }

    async event void UartStream.sendDone(uint8_t *buf, uint16_t len, error_t
error){
        atomic{
            if (error==SUCCESS){
                //printf("ALL RIGHT!! Bytes sent\n");
                //printf("Sent # %ld bytes\n", (uint32_t) len);
                //printf("sent values = %i, %i, %i,
%i.\n",buf[0],buf[1],buf[2],buf[3]);
                //printfflush;
            } else {
                call Leds.led2On();
                //printf ("ERROR in sending bytes over UART\n");
                //printfflush();
            }
        call Resource1.release();
        }
    }


}


//***************************** And then, if you want to try the
application, this is the BlinkToRadio.h

 #ifndef BLINKTORADIO_H
 #define BLINKTORADIO_H

 enum {
   TIMER_PERIOD_MILLI = 1000,
   AM_BLINKTORADIOMSG = 6
 };


 typedef nx_struct BlinkToRadioMsg {
    nx_uint16_t nodeId;
    nx_uint8_t byte1;
    nx_uint8_t byte2;
    nx_uint8_t byte3;
    nx_uint8_t data[66];
 }BlinkToRadioMsg;

 #endif


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

Reply via email to