Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: Serial format

2005-03-16 by fjch100

This is my code:

unsigned char Rxindex;
unsigned char Rxbuffer[11];
unsigned char frec_buffer[12];
unsigned char ad_volt[13];

union ad9850_data {
unsigned long ldata;
unsigned char cdata[4];
};
unsigned char ad9850_control=0; //control byte for AD9850,
union ad9850_data ad9850_frec; //frecuency data(32 bits) for AD9850



void RF_commander(unsigned char rscomd){

unsigned char combuffer2, i;

if ((rscomd>13) && (rscomd<123)) {
    Rxbuffer[Rxindex]=rscomd;
    uart_putc(rscomd);              //transmit LSB to PC
    if (Rxindex>10) {               //check if Rxindex<12
        Rxindex=0;                  //
        clear_Rxbuffer();
    }
    else Rxindex++;
return;
}

if (rscomd==13){
switch(Rxbuffer[0])
    {

    //! command An = adquire A/D(n) and sent in ASCII to PC
    //if (Rxbuffer[0]=="A")
    case 65:  //!"A"=65
     .
     .
     .
     break;

//! F0x89ABCDEF = "F" + 4 bytes(32 bits) ->  
//set frecuency to 89ABCDEF Herz

    //if (Rxbuffer[0]=="F")
    case 70:  //!"F"=70
       for (i=0;i<(Rxindex+1);i++) {
            ad9850_frec.cdata[i]=Rxbuffer[(i+1)];
        }

       /*for (i=0;i<(Rxindex+1);i++) {
            frec_buffer[i]=Rxbuffer(i+1)];            
                //eliminate "F"
        }  
        Rxindex--;                                  //dec index
        uart_putc(10);                             // new line
        uart_putc(13);                             // CR
        uart_puts_p(PSTR("Frec = "));
        uart_puts(ltoa(ad9850_frec.ldata,ad_volt,10));
        uart_puts_p(PSTR(" Hz"));
        uart_putc(10);                             // new line
        uart_putc(13);                             // CR
        Rxindex=0;
        clear_Rxbuffer();
        break;




to test: in hyperterminal I put:
F0001(ASCII) + Return = 0x30303031hex = 808464433dec
and the AVR return the bytes in reverse order "1000" 
but in binary = 0x31303030hex = 825241648dec




--- In AVR-Chat@yahoogroups.com, "brewski922" <brewski@i...> wrote:
> 
> --- In AVR-Chat@yahoogroups.com, "fjch100" <fjch100@c...> wrote:
> > 
> > HI,
> > I have a question:
> > when I sent a Long(4 bytes) variable from the PC to the AVR 
which 
> > byte is first? LSB ? MSB ?
> > and if a need to sent a Long from the AVR to the PC USART (with 
a 
> > Borland Delphi program) what byte is needed to be first? LSB ? 
MSB?
> > 
> > also I´m using WINAVR GCC, my LCD rutine is with printf, how can 
I 
> > set the GCC to use LCD & USART simutaneusly with 
printf/fdevopen ?
> 
> That depends on the protocol. If you are sending a file you are 
> sending binary info. I know nothing about how programs do that but 
I 
> have written programs that an AVR sends command "B0102\r" 
consisting 
> of 5 ASCII characters followed CR, another ASCII.
> 
> The equipment that receives this command is a Audio/Video 
switcher. 
> The switcher is expecting the command to consist of 
> A=Audio V=Video B=Both
> Outport port, there are 2, 01 and 02
> Input port, there are 8, 01 through 08
> Carriage Return
> 
> In the above I'm switching Both, to Output 1, from Input 2.
> 
> I'm using CodeVision and the above string is stored in Flash as
> flash char    S12[]="B0102\r";
> When the appropriate pushbutton is pushed the above string is sent 
> out the serial port. The fact that the switcher changes correctly 
as 
> commanded proves that that string arrives at the switcher exactly 
as 
> it is stored in Flash with the exception that the '\r' is replaced 
> with a CR.
> 
> The fact that you are sending bytes may be the problem. 
> 
> Could you show us a snippet of your code?
> 
> Mike

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.