SERIAL INTERRUPT NOT WORKING PROPERTY

// funciona enviando la información a través de Host (18F2550 & Cy2196R) 

#include "mbed.h"

Serial RF(p13,p14);

PwmOut SERVO1(p21);
PwmOut SERVO2(p22);
PwmOut SERVO3(p23);
PwmOut SERVO4(p24);
PwmOut SERVO5(p25);
PwmOut SERVO6(p26);

DigitalOut myled(LED1);

int pos[6]={100,100,100,100,100,100};
char tramain[3]={0,0,0};

void servopos(){
    if (tramain[0]=='C'){ pos[tramain[1]]=tramain[2]; myled=1; }
    else {myled=0;}
}

void Rx_Interrupt(){
    tramain[0]=RF.getc(); tramain[1]=RF.getc(); tramain[2]=RF.getc(); 
    servopos(); 
}

int main() {
    RF.baud(19200);
    SERVO1.period_us(20000);
    RF.attach(&Rx_Interrupt, Serial::RxIrq);
    
    while(1){
        SERVO1.pulsewidth_us(pos[0]*10);
        SERVO2.pulsewidth_us(pos[1]*10);
    }
}

Hi, I have made this code to control servos via RF, works well but after a while apparently reading overflows disruption to shipping though the plot correctly, after a while it works again. I know because i see the activity in "led".

23 Oct 2011

Try using MODSERIAL (it makes it easy to add interrupts and a software buffer on serial ports)

see http://mbed.org/cookbook/MODSERIAL

Without interrupts and a large buffer you can drop characters at high baud rates

see http://mbed.org/cookbook/Serial-Interrupts for info on how this happens.

You should probably only read in one character in the interrupt routine and buffer three in software in the main routine.

/media/uploads/Robo3001/sin_t-tulo.png

// funciona enviando la informaci�n a trav�s de Host (18F2550 & Cy2196R) 

#include "mbed.h"

Serial RF(p13,p14);
Serial PC(USBTX,USBRX);

PwmOut SERVO1(p21);
PwmOut SERVO2(p22);
PwmOut SERVO3(p23);
PwmOut SERVO4(p24);
PwmOut SERVO5(p25);
PwmOut SERVO6(p26);

DigitalOut myled(LED1);

int pos[6]={157,138,157,138,157,138};
char tramain[3]={0,0,0};

void servopos(){
    if (tramain[0]=='C'){ pos[tramain[1]]=tramain[2]; myled=1;}
    else {myled=0;}
}

/*void Rx_Interrupt(){
    tramain[0]=RF.getc(); tramain[1]=RF.getc(); tramain[2]=RF.getc(); 
    servopos(); */


int main() {
    RF.baud(19200);
    PC.baud(19200);
    SERVO1.period_us(20000);
    //RF.attach(&Rx_Interrupt, Serial::RxIrq);
    
    while(1){
        if (PC.readable()){ tramain[0]=PC.getc(); tramain[1]=PC.getc(); tramain[2]=PC.getc(); servopos();}    
        if (RF.readable()){ tramain[0]=RF.getc(); tramain[1]=RF.getc(); tramain[2]=RF.getc(); servopos();}    
        SERVO1.pulsewidth_us(pos[0]*10);
        SERVO2.pulsewidth_us(pos[1]*10);
        SERVO3.pulsewidth_us(pos[2]*10);
        SERVO4.pulsewidth_us(pos[3]*10);
        SERVO5.pulsewidth_us(pos[4]*10);
        SERVO6.pulsewidth_us(pos[5]*10);
    }
}

This code work good for a CDC or SERIAL OVER USB but when i change to RF this come down. And here i'm not using interrupts... maybe it's a problem about transceiver or CDC USB MICROCHIP MASTER. https://www.facebook.com/photo.php?fbid=10150877018340567&set=a.10150264313190567.499965.853030566&type=3

I hope not cause problems if I go this code, I just do with the desire to understand that I do on the side of the pc

#include <18f2550.h>                                 // declarar pic18f2550

#fuses HSPLL
#fuses NOWDT
#fuses NOPROTECT
#fuses NOLVP
#fuses NODEBUG
#fuses USBDIV
#fuses PLL5
#fuses CPUDIV1
#fuses VREGEN
#fuses NOMCLR     // fuses
#use delay(clock=48M)                                // clock  a 48Mhz

#use rs232(baud=19200, xmit=PIN_C6,rcv=PIN_C7, stream=RF1)

#include <usb_cdc.h>                            // declaro librerias USB
#include <usb_desc_cdc.h>                       // declaro librerias USB

void main() {

usb_cdc_init();
usb_init(); //inicializamos el USB

while (!usb_cdc_connected()) {}
   while (true)
   {
      usb_task();
      if(usb_enumerated()) 
      {
         if (usb_cdc_kbhit()){ 
            putc(usb_cdc_getc(),RF1);
         }
   
         if (kbhit(RF1)){
            usb_cdc_putc(getc(RF1));
         }
      }
   } 
}

Regarding the comment that was used in the main program variables to avoid overflow. Well I'll try wiring the UART, which was earmarked for the RF.

Thanks.

I had also tried wiring the UART port and it works perfectly with all codes, then the problem is not in the Mbed. Well well thank you.

14 Nov 2011

I would like to make a program in C (computer side) that can operate one or several bits by using USB Conncetor.

and other program shuold be on the LPC. Do anyone can help me and give me some eamples PLEASE?