Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:19 16 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : shiftout, shiftin in MMBasic (MMite)

Author Message
drkl

Senior Member

Joined: 18/10/2015
Location: Hungary
Posts: 102
Posted: 01:03am 04 Mar 2016
Copy link to clipboard 
Print this post

Hello,

How can realize the arduino
shiftOut(dataPin, clockPin, bitOrder, value)
byte incoming = shiftIn(dataPin, clockPin, bitOrder)
commands in Micromite MMBasic? Cfunctions?

(simple and quick method...)
drkl
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1577
Posted: 09:35pm 04 Mar 2016
Copy link to clipboard 
Print this post

  drkl said  [...] (simple and quick method...)drkl


As simple and quick as SPI (+ bit order reversal)? I would try that.

Regards MichaelEdited by twofingers 2016-03-06
causality ≠ correlation ≠ coincidence
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 12:23am 05 Mar 2016
Copy link to clipboard 
Print this post

Hi drkl,

Haven'the got actual code but the process would be


choose byte to output
for x = 1 to 8
get bit 0 by masking byte with binary 00000001
output bit to data pin
pulse clock pin
rotate byte clockwise 1 bit
next



To find a rotate routine, Have a look in the MMBASIC library,
cheers,
Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 12:22am 06 Mar 2016
Copy link to clipboard 
Print this post

Hi Konya,

Further to my last post, the following 5.0 code should clock out a byte serially, lsb first, although I haven't actually run the code. The receiver should monitor the clock pin and on a 0 to 1 transition, sample the data pin.



' Sample code to clock a byte out serially, lsb first.
'
' a bit of setup code for this example - normally your program would have
' done this before calling the sub routine
'
' define dat and clock pins as digital outputs
setpin datapin,DOUT ' any digital out pins for clock and data
setpin clkpin,DOUT
pin(clkpin)=0 ' clock pin to 0 to start
' example byte to output
sobyte% = &H10100101

' sub routine to clock out byte
sub shift_byte_out (sobyte%,datapin,clkpin,x)
local sobyte%,dpin,cpin,sobit%
dpin = datapin
cpin = clkpin
for x = 1 to 8
sobit% = &H00000001 AND sobyte% ' mask and select lsb
sobyte% = sobyte% >> 1. ' shift byte 1 bit place right
if setbit% = 0 then
pin(datapin) = 0
else
pin(datapin) = 1
endif
pause 1. ' wait for data pin to stabilize - a guess?
pin(cpin) = 1 ' pulse the clock pin
pause = 1 ' 1mS clock width
pin(cpin) = 0
pause 1 ' set this to determine clock speed
next x. ' loop through 8 bits
end sub



The shift in routine will be similar, maybe interrupt on a low to high clock then sample data line in an 8 bit loop.

Hope this helps,
Doug.

[EDIT} Fixed a couple of errors in code. D.

Edited by panky 2016-03-07
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
drkl

Senior Member

Joined: 18/10/2015
Location: Hungary
Posts: 102
Posted: 08:57pm 06 Mar 2016
Copy link to clipboard 
Print this post

Dear Panky,

Thank you for your work, and code (with some minor bugs ),
but I think the best solution is using the software spi published by Geoff
in ver 5.x material.
When I finished and tested the code, I'll publish in this topic.

Many thanks,
drkl
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025