View previous topic :: View next topic |
Author |
Message |
sandy wilson
Joined: 25 Feb 2004 Posts: 28
|
Transmission of 32bit number on uart |
Posted: Wed Mar 03, 2010 6:40 am |
|
|
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 |
Posted: Wed Mar 03, 2010 7:16 am |
|
|
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 |
Posted: Wed Mar 03, 2010 7:18 am |
|
|
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 |
Posted: Wed Mar 03, 2010 7:21 am |
|
|
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 |
Posted: Wed Mar 03, 2010 7:28 am |
|
|
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
|
|
Posted: Wed Mar 03, 2010 8:45 am |
|
|
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
|
|
Posted: Wed Mar 03, 2010 9:37 am |
|
|
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.
I'll need to talk to the board supplier to see what they do.
Thanks for your help
Sandy Wilson |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Mar 03, 2010 9:52 am |
|
|
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
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. |
|
|
|