View previous topic :: View next topic |
Author |
Message |
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat Nov 23, 2013 4:34 am Post subject: Little Endian Byte Format ??? |
|
|
I've been experimenting with a module that requires Bytes to be sent as follows:
Quote: | In this case, the command should look like:
[A4][03][42]
The bit order and USART details should follow relatively standard parameters:
8 Bits per Transfer, 1 Stop Bit, Least Significant Bit Sent First
So, for example, A4 (10100100) should be sent from first bit to last -> 00100101. This is the same for all bytes.
|
The only way I can think of to do this is by:
Code: | $regfile = "m328def.dat"
$crystal = 8000000
$baud = 38400
$hwstack = 128
$swstack = 128
$framesize = 128
$sim
Dim Xy As Byte , Ba As Byte , I As Byte , J As Byte
Xy = &HA4
For I = 0 To 7
J = 7 - I
Ba.i = Xy.j
Next
Print Bin(xy) ; " " ; Bin(ba)
end 'end program
|
Is there a better/easier way to do this ????
Thanks, Ennio M
(BASCOM-AVR version : 2.0.7.7 , Latest : 2.0.7.6 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Sat Nov 23, 2013 12:42 pm Post subject: |
|
|
little and big endian describe the storage of the byte order when multiple bytes are used. So for example dim W as word . W will use 2 bytes which will use address &H100 and &H101.
Little endian which bascom uses stores the LSB (least significant byte) at &H100 (the lowest address). Thus if W has a value of 1, the 1 would be placed at address &H100.
The bit order itself is not reversed. Thus 1 will be &B00000001 in both little and big endian. That is, to my knowledge.
So i wonder if it is just enough when you reverse the byte order?
It does not make sense to me that a serial device would mirror all bits?
While you can mirror the bits you have no control of the start and stop bits. So in such a case shiftout would work nice. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Nov 23, 2013 4:02 pm Post subject: Re: Little Endian Byte Format ??? |
|
|
enniom wrote: | The only way I can think of to do this is by: |
Shooting the horse from the back?
Why don't you link the thread, where you got it from? ANT-forum:
http://www.thisisant.com/forum/viewthread/3612
Quote: | Least Significant Bit Sent First |
Better would have also been, if you'd have checked Wiki:
http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
Quote:
Quote: | The right-most (least significant) data bit is always transmitted first. ... |
So it seems to be pretty UART standard behavior, nothing to worry about.
The only confusing sentence in Mod Harrison's post, ANT-forum:
Quote: | So your A4 should be (as sent in order from first to last) -> 00100101. This should be the same for all bytes. |
should tell imho that if you bitbang the bits out, the lsbit has to be banged first. But that's what the UART already takes care of.
However I feel, you'd better have had a follow up post in the ANT-forum to clear things up, instead having the users here taking blind shots about a device, you don't even tell them about. |
|
Back to top |
|
|
enniom
Joined: 20 Oct 2009 Posts: 537
|
Posted: Sat Nov 23, 2013 10:03 pm Post subject: |
|
|
Thanks Mark. I think your little endian explanation on multiple bytes is correct.
And MWS ... as usual you have much understanding on these issues than the rest of us forum members (the horse got away). Interesting that (at least) we have similar interests.
As always, thanks for your help. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Nov 23, 2013 10:30 pm Post subject: |
|
|
Ennio,
enniom wrote: | Interesting that (at least) we have similar interests. |
if you mention uC's, yes, we have the same interests. In regards of ANT I have to disappoint you, I found the forum as I've googled a sentence from your post, searching for a data sheet.
As in most cases I build up my response on founded information, I was looking there for such, but I'd have to log in to get some. The explanation about the UART's mode of operation seemed the easier way to go.
You're welcome. |
|
Back to top |
|
|
|