---------- Forwarded message ----------
From: Ronald Eliseo Reyes López <[email protected]>
Date: 2010/9/8
Subject: Problems to receive data via Usart on telosb
To: [email protected], [email protected]
Hello ... First of all apologize for bothering them directly, but really I
need your help!!
I was using UartStream Uartbyte and then the HplMsp430Usart interfaces,
and so far I can only receive one byte via the usart module.
I have an external module connected to my telos via U2 extension port,
using the uart0TX, RX and the userINT terminals.
The idea is to send commnad to the module via uart, to make the module
use one of the sensors attached to it and then, when the measure has
done, interrupt the mote to get the usart resource, once the resource
is granted the mote sends a petition to the external module to receive
the measures, the petition is sent without problems, but the mote just
receive 1 byte from the module! I found that the module sent all the
45 bytes to the mote, the module is not the problem, the problem is
the reception at the mote...
I'll be very thankful if you can take a look to my code and give some
tips...
#include <lib6lowpan.h>
module MapaC {
uses {
interface Boot;
interface Init as Hardware;
interface Mapa as ModAdq;
interface Leds;
interface Timer<TMilli> as Temp;
interface SplitControl as PilaIP;
interface UDP as SocketRedSensado; }
}
implementation {
uint8_t orden = 0x30;
uint8_t* punt_orden = &orden;
event void Boot.booted() {
call Hardware.init();
call PilaIP.start();
}
event void PilaIP.startDone( error_t error ) {
call Leds.led1On();
call Temp.startOneShot(5120);
}
event void PilaIP.stopDone( error_t error ) { }
event void SocketRedSensado.recvfrom( struct sockaddr_in6 *remitente, void
*datos, uint16_t longitud, struct ip_metadata *meta ) { }
event void Temp.fired() {
if( call ModAdq.enviarComando( punt_orden ) == SUCCESS ) {
call Leds.led1Off();
call Temp.startOneShot(30720); }
else
call Leds.led0On();
}
async event void ModAdq.enviarComandoDone( error_t result ) {
if( result != SUCCESS )
call Leds.led0On();
}
async event void ModAdq.medicionesListas( uint8_t* med, uint16_t lon,
error_t result ) {
if( result != SUCCESS )
call Leds.led0On();
else
call Leds.led1On();
}
}
onfiguration MapaAppC { }
implementation {
components MapaC;
components MainC;
MapaC.Boot -> MainC;
components HalMapaC;
MapaC.ModAdq -> HalMapaC;
MapaC.Hardware -> HalMapaC;
components LedsC;
MapaC.Leds -> LedsC;
components new TimerMilliC();
MapaC.Temp -> TimerMilliC;
components new UdpSocketC() as RedSensado;
MapaC.SocketRedSensado -> RedSensado;
components IPDispatchC;
MapaC.PilaIP -> IPDispatchC;
}
#include "printf.h"
#include "Mapa.h"
#include "msp430usart.h"
#define CANT_MAX 1
module HalMapaP {
provides interface Mapa;
uses {
interface HplMsp430Interrupt as FDM;
interface Resource as RecursoUsart;
interface HplMsp430Usart as Usart;
interface HplMsp430UsartInterrupts as UsartInt; }
}
implementation {
bool ocupado = FALSE;
bool adquirido = FALSE;
uint8_t contador;
uint8_t comando;
uint8_t auxiliar;
uint8_t* punt_paq;
mapa_tarea_t tarea;
mapa_error_t error;
mapa_info_t estado;
mapa_paq_t paq_med;
mapa_paq_t* punt_paq_med = &paq_med;
task void sen_evento() {
uint8_t tarea_l;
atomic
tarea_l = tarea;
switch( tarea_l ) {
case ENVIAR:
atomic
signal Mapa.enviarComandoDone(estado.result);
break;
case RECIBIR:
atomic
signal Mapa.medicionesListas(estado.buf,estado.lon,estado.result);
break; }
}
task void ind_error() {
uint8_t error_l;
uint8_t auxiliar_l;
atomic {
auxiliar_l = auxiliar;
error_l = error; }
switch( error_l ) {
case REC_OCUP:
printf("Recurso Ocupado\n");
break;
case MOD_OCUP:
printf("Modulo Ocupado\n");
break;
case FALLO_LIB_REC:
printf("Fallo al liberar el Recurso\n");
break;
case FALLO_TOMA_REC:
printf("Fallo al tomar el Recurso\n");
break;
case FALLO_ACK:
printf("ACK no recibido\n");
case RCP:
printf("Dato, %x\n", auxiliar_l);
break;
}
printfflush();
}
void act_int() {
atomic {
call FDM.disable();
call FDM.clear();
call FDM.edge(TRUE);
call FDM.enable(); }
}
void desact_int() {
atomic{
call FDM.disable();
call FDM.clear(); }
}
void liberar_recurso() {
adquirido = FALSE;
if( call RecursoUsart.release() != SUCCESS ) {
error = FALLO_LIB_REC;
post ind_error(); }
}
error_t uart_enviar( uint8_t* byte ) {
atomic{
call Usart.tx( *byte );
call Usart.clrTxIntr();
call Usart.enableTxIntr(); }
return SUCCESS;
}
error_t uart_recibir() {
atomic{
call Usart.clrRxIntr();
call Usart.enableRxIntr(); }
return SUCCESS;
}
async event void UsartInt.txDone() {
if( adquirido ) {
call Usart.disableTxIntr();
if( !call FDM.getValue() ) {
estado.result = SUCCESS;
if( tarea == ENVIAR ) {
act_int();
liberar_recurso();
post sen_evento(); }
else if( tarea == RECIBIR )
uart_recibir(); }
else {
atomic {
error = FALLO_ACK;
estado.buf = NULL;
estado.lon = 0;
estado.result = FAIL;
ocupado = FALSE; }
liberar_recurso();
post sen_evento();
post ind_error(); }}
}
async event void UsartInt.rxDone( uint8_t dato ) {
if( adquirido ) {
*( punt_paq + contador++ ) = dato;
error = RCP;
auxiliar = dato;
post ind_error();
if( contador == CANT_MAX ) {
call Usart.disableRxIntr();
atomic {
estado.buf = (uint8_t*)punt_paq_med;
estado.lon = CANT_MAX;
estado.result = SUCCESS;
ocupado = FALSE; }
liberar_recurso();
post sen_evento(); }
}
}
async event void FDM.fired() {
desact_int();
contador = 0;
comando = 0xAA;
tarea = RECIBIR;
punt_paq = (uint8_t*)punt_paq_med;
if( call RecursoUsart.request() != SUCCESS ) {
atomic {
error = FALLO_TOMA_REC;
estado.buf = NULL;
estado.lon = 0;
estado.result = FAIL;
ocupado = FALSE; }
post sen_evento();
post ind_error(); }
}
event void RecursoUsart.granted() {
atomic {
adquirido = TRUE;
call Usart.setModeUart( (msp430_uart_union_config_t*) &uart_config );
uart_enviar( &comando ); }
}
async command error_t Mapa.enviarComando( uint8_t* orden ) {
bool condicion = FALSE;
atomic
condicion = !ocupado && call FDM.getValue();
if( condicion ) {
if( call RecursoUsart.request() == SUCCESS ) {
atomic {
ocupado = TRUE;
comando = *orden;
tarea = ENVIAR; }
return SUCCESS; }
else {
atomic
error = REC_OCUP;
post ind_error();
return ERETRY; }}
else {
atomic
error = MOD_OCUP;
post ind_error();
return EBUSY; }
}
default async event void Mapa.enviarComandoDone( error_t result ) { }
default async event void Mapa.medicionesListas( uint8_t* mediciones,
uint16_t lon, error_t result ) { }
}
configuration HalMapaC {
provides {
interface Init as Hardware;
interface Mapa; }
}
implementation {
components HalMapaP as MapaP;
Mapa = MapaP;
components HplMapaUsartC as UsartC;
MapaP.RecursoUsart -> UsartC;
MapaP.Usart -> UsartC;
MapaP.UsartInt -> UsartC;
components HplMapaPinsC as PinsC;
MapaP.FDM -> PinsC.FDM;
Hardware = PinsC;
}
Thanks in advance...
Ronald
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help