Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Array of Long

2009-03-06 by Raymond Hurst

You need to do something similar to this:

long test[10] = {....};

UDR = ((char)test[i]) & 0xFF;
UDR = ((char)test[i] >> 8) & 0xFF;
UDR = ((char)test[i] >> 16) & 0xFF;
UDR = ((char)test[i] >> 24) & 0xFF;
i += 1;

David VanHorn wrote:
> 
> 
> I am a bit puzzled. (and new to working in C)
> 
> I have an array of longs that I need to feed out my Uart.
> Obviously the uart can't take more than a char.
> 
> The code below shows some of the ideas I've tried, but in all cases,
> the ASM shows me that the pointer will be bumped four bytes, not one.
> 
> What's the best way to get this data to my Uart?
> 
> Yes, I CAN sit and spin for the UDR to be ready.
> 
> void Do_Serial_Output(void)
> {
> unsigned char i = 0;
> unsigned char t = 0;
> if (0 < Proc_Data_Size) { // If there's data to send..
> while ( i<4 ) {
> while (!(UCSRA & (1<< UDRE))) {}
> //memcpy(&t,&(Proc_Data[Proc_Data_Out_Index])+i,1);
> //UDR = t;
> //UDR = (char)(*((char*)(&(Proc_Data[Proc_Data_Out_Index])+i)));
> UDR = &(Proc_Data[Proc_Data_Out_Index])+i;
> ++i;
> }
> 
> Proc_Data_Size--;
> Proc_Data_Out_Index++;
> if (Proc_Samples < Proc_Data_Out_Index) Proc_Data_Out_Index =
> 0; // Handle wrap
> }
> }
> 
> -- 
> 
> "The very powerful and the very stupid have one thing in common. Instead of
> altering their views to fit the facts, they alter the facts to fit their
> views... which can be very uncomfortable if you happen to be one of the
> facts that needs altering." Doctor Who, Face of Evil
> 
> 

-- 
Ray Hurst
949-202-6037

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.