View Full Version : SHIFTOUT MSB/LSBFIRST clarification
iw2fvo
- 26th May 2021, 16:15
good day to all in this forum,
I am using PicBasic pro to load an 8 bit shift register and I wrote a very simple program like this:
INCLUDE "MODEDEFS.BAS"
DT var byte
DT=128 ' decimal
SHIFTOUT H_DATA,H_CLK,msbfirst ,[DT\8]
Then I do suppose that the MSB ( in this case "1" ) is transmitted first and then "0000000" is transmitted after it.
By looking to the output stream with a scope, I find that the bit at logic level = high ( dec 128) is shown to the left side of the scope and not at the right side of the scope display.
I am just a little bit confuesd about that: any clarification please ?
Thanks in advance.
bye
peterdeco1
- 26th May 2021, 19:13
I haven't done this in a long time but here is a snippet of code I used to send by SPI to a device:
Low PORTA.3 : Pause 10 'CHIP SELECT
ShiftOut PORTC.5,PORTC.3,0,[9254\16] 'playconfig0
ShiftOut PORTC.5,PORTC.3,0,[114\8] '1st play byte
High PORTA.3 : Pause 10 'deselect - end of word
The 0 after portc.3 means send code LSB. A 1 would send it MSB.
iw2fvo
- 26th May 2021, 20:37
thanks a lot,
Is your SPI device set to receive MSBfirst or LSBfirst please ?
Bye
richard
- 26th May 2021, 23:24
time on a scope flows from left to right
9052
iw2fvo
- 27th May 2021, 10:14
I am so sorry Richard:
if the time flows from left to right, then the first bit sent should be on the right and not to the left of the scope !
Where am I wrong please ?
Bye
richard
- 27th May 2021, 10:27
which second was recorded first in time sequence ?
9053
richard
- 27th May 2021, 10:29
slow your timbase right down , what direction does the dot travel
the dot having writ moves on
iw2fvo
- 27th May 2021, 12:04
the first bit sent out by the pic should be on the right ( 9 seconds old )
The last bit sent by the pic should be on the left ( 0 seconds old )
I am sorry for not understanding...
thanks
richard
- 27th May 2021, 12:40
last try
9054
iw2fvo
- 27th May 2021, 13:23
thanks again,
I am sorry for not understand...
If I slow down the scope time base the dot goes from left to right.
So the first bit transmitted by the PIC is always to the right of the scope and the last transmitted by the PIC is shown to the left.
Am I right ?
Then the 9 seconds old bit is the first transmitted by the PIC.
The 0 secs old bit is the last transmitted by the PIC.
Is it right ?
Thanks
iw2fvo
- 27th May 2021, 13:25
sorry: I did not tell that I am talking about the PIC output .
Thanks
richard
- 27th May 2021, 14:13
completely wrong , the first bit is on the left
iw2fvo
- 27th May 2021, 16:04
could you please check in the real situation:
connect the PIC DATA output to scope ch_1
connect the PIC clock output to scope ch_2 and set the trigger to this channel.
Tranmit bin 00000011 ( dec 3 ) \8 selecting MSB FIRST. and insert a small delay in the main loop just for better scope triggering. My scope is a old style !
What do you see on the scope ? 00000011 or 11000000 ?
Or better: do you see "11" to the right side or to the left side of the scope ?
Thanks for helping
regards
peterdeco1
- 27th May 2021, 16:54
You will send 00000011.
iw2fvo
- 27th May 2021, 17:03
Hi Peter,
could you please clarify better ?
( my English is not a first language )
Thanks
iw2fvo
- 27th May 2021, 17:24
iT IS MY FAULT:
Richard explanation is correct as usual !
Thanks for all.
All the best
regards,
Bye
Ioannis
- 5th June 2021, 21:10
In the first post you said the number was 128 (10000000 in binary) so the MSB is indeed a '1'.
But on the last post you saw a number 3 (00000011 in binary) so the MSB is a '0'.
Ioannis
iw2fvo
- 6th June 2021, 08:36
thanks for the response,
I had on my mund a shift register that will receive the serial stream from the PIC and I did associated the scope display to the shift register...
I was in error when I thought that the first bit on the left hand side of the scope is the last transmitted by the PIC: the first bit bit on the left of the scope is the first transmitted and the last bit to the right is the last transmitted.
Again, it was my fault .
Thanks for the assistance.
regards,Bye
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.