CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Transmission of 32bit number on uart

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sandy wilson



Joined: 25 Feb 2004
Posts: 28

View user's profile Send private message

Transmission of 32bit number on uart
PostPosted: Wed Mar 03, 2010 6:40 am     Reply with quote

Hello,

Can anybody tell me if it is possible to transmit a 32 bit unsigned integer over the PIC uart. If no does any body have any suggestions on how to do it?
Guest








Re: Transmission of 32bit number on uart
PostPosted: Wed Mar 03, 2010 7:16 am     Reply with quote

sandy wilson wrote:
Hello,

Can anybody tell me if it is possible to transmit a 32 bit unsigned integer over the PIC uart. If no does any body have any suggestions on how to do it?


you wish to transmit 32 bits?
Guest








Re: Transmission of 32bit number on uart
PostPosted: Wed Mar 03, 2010 7:18 am     Reply with quote

Anonymous wrote:
sandy wilson wrote:
Hello,

Can anybody tell me if it is possible to transmit a 32 bit unsigned integer over the PIC uart. If no does any body have any suggestions on how to do it?


you wish to transmit 32 bits?


I think 8*4=32

After calculators were invented I forgot multiplication tables
Guest








Re: Transmission of 32bit number on uart
PostPosted: Wed Mar 03, 2010 7:21 am     Reply with quote

Anonymous wrote:
Anonymous wrote:
sandy wilson wrote:
Hello,

Can anybody tell me if it is possible to transmit a 32 bit unsigned integer over the PIC uart. If no does any body have any suggestions on how to do it?


you wish to transmit 32 bits?


I think 8*4=32

After calculators were invented I forgot multiplication tables


You can't use a standard rs232 type UART for this. You would either
have to transmit the data in chunks of 8 bits each, or you would have
to switch to a custom signalling scheme. One method would be to
complement each bit with its inverse, so that a valid bit clock can be
recovered at the receiver. Another method is convolutional coding,
which has the additional benefit of (limited) error correction
capabilities.
Guest








Re: Transmission of 32bit number on uart
PostPosted: Wed Mar 03, 2010 7:28 am     Reply with quote

Anonymous wrote:
Anonymous wrote:
Anonymous wrote:
sandy wilson wrote:
Hello,

Can anybody tell me if it is possible to transmit a 32 bit unsigned integer over the PIC uart. If no does any body have any suggestions on how to do it?


you wish to transmit 32 bits?


I think 8*4=32

After calculators were invented I forgot multiplication tables


You can't use a standard rs232 type UART for this. You would either
have to transmit the data in chunks of 8 bits each, or you would have
to switch to a custom signalling scheme. One method would be to
complement each bit with its inverse, so that a valid bit clock can be
recovered at the receiver. Another method is convolutional coding,
which has the additional benefit of (limited) error correction
capabilities.


The receive/shift solution:

Code:
uint32 data= 0;

for ( i = 0; i < 8; i++ )
{
data<<= 8;
data |= (uint8_t)get_uart_data();
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 03, 2010 8:45 am     Reply with quote

We need to know what's on the other end of the line ! Another PIC, a PC,?? As well, distance between units.
One way ,as others have said, transmit 4 bytes to the other end. Have the other end reconstruct the 4 bytes into the 32bit value.
Another way is to create your own 32 bit software uart,again a simple task,especially nice if talking PIC to PIC
I prefer the 'roll your own' approach,have used it for the past 20 years communicating with remotes for over 20 miles of copper.
Jay
sandy wilson



Joined: 25 Feb 2004
Posts: 28

View user's profile Send private message

PostPosted: Wed Mar 03, 2010 9:37 am     Reply with quote

Hello Everybody,

thanks for all of the input.

I am planning to talk to a motor contoller PCB and to set some of its registers you need to pass it a 32 bit number. The spec says it will do it over RS232 but for the life of me I couldn't see how to do it except for rebuilding the data at the receiver similar to guests suggestion.

I posted the question because I thought I was just being stupid and missing something. Confused

I'll need to talk to the board supplier to see what they do.

Thanks for your help


Sandy Wilson Confused
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Mar 03, 2010 9:52 am     Reply with quote

It will either be done in ASCII or as 4 bytes e.g.

Code:

    int32 val = 12345;
    printf("uL\r", val);

This will send the ASCII chars '1', '2', '3', '4', '5' over the UART. Will proberbly need a terminating char such as '\r' as shown.

The second method can be done in several ways.
Code:

    // With a pointer
    int32 val = 12345;
    int8 *p;
   
    p = &val;
    putc(*p++);
    putc(*p++);
    putc(*p++);
    putc(*p++);

This will send the hex values 0x00, 0x00, 0x30, 0x39 to the device.
I proberbly got the order wrong Smile
You need to find out which order (little or big endian) that the device requires.
Code:

    // With a union
    union {
        int32 val;
        int8[4];
    } myVal;

    myVal.val = 12345;
   
    putc(myVal[0]);
    putc(myVal[1];
    putc(myVal[2]);
    putc(myVal[3]);


it can also be done with a union and struct to access the individual bytes.

Anyway, something like that.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group