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 : MicroMite CFunction SPIPort behaving oddly
Author | Message | ||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
Morning Forum. On a MicroMite Mk2 28 pin 170, has anyone had any joy getting the SPIPort routine in the Embedded routines in the firmware pack working? (can't use the normal SPI port). I have something very odd happening whereby I am getting the CS pin oscillating even when I have stopped the program and am at the > prompt. Here is my sub to talk to the chip: Sub MAX7221(MAX7221Dat As Integer) Local Integer j Pin(CS)=0 'CS Lo j=SPIPort(2,DAT,CLK,MAX7221Dat,0,0,16)' 16 bits sent at 1MHz+ Pin(CS)=1 'CS Hi End Sub If I REM the line starting j= then I see the toggle from the CS pin, but if I un-REM it, I get the oscillation, even when my prog is not running. It starts up, makes a single call to the above Sub then ENDs, but that CS pin keeps waggling... at the > prompt(!). HWInit: Pin(CS)=1:SetPin CS,DOUT,OC' pin 14 =CS Pin(DAT)=0:SetPin DAT,DOUT,OC ' set tx pin low then set it as an output Pin(CLK)=0:SetPin CLK,DOUT,OC ' set clk pin low then set it as an output SetPin 2, DIN ' dummy input pin InitMAX7221: MAX7221(&H0F01)' display normal (not test) End I have noticed a disparity in the SPIPort PDF, the header for the Function shows: CFunction SPIPort(integer, integer, integer, integer) integer which suggests four arguments passed to it, but the example shows rd = SPIPort( rx, tx, clk, data_to_send, speed, mode, bits ) which shows seven arguments. I used the example in my code as you can see. I tried changing the CFunction definition to include seven integers passed in but no different. Bit stuck, any help/pointers greatly appreciated. |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
It very much looks something is repeatedly calling your sub. The CS low time is about 250uS which is about correct if the line starting j= is commented out. I did a lot of testing of that CFunction and it worked fine. Geoff. Geoff Graham - http://geoffg.net |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
I agree, but it is happening at the > prompt, which kind of points to some backdoor thing going on. Also, I call the routine once then end and it still continues. I am up against the clock here and I am now etching a tiddly level shifter so I can use the hardware SPI. The MAX7221 needs a a min 3.5V to recognise a hi, so direct wired doesn't cut it. Thought I could be clever using some 5V tolerant pins with pull-ups and the SPIPort function, I have to get this out the door tonight One thing I didn't try was flashing the firmware, I tend to do that if I get weirdness (rarely) Thanks for quick response h Edited 2020-05-21 00:19 by CaptainBoing |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
Do you have a tick timer going off every millisecond? That will keep running at the command prompt. Geoff Geoff Graham - http://geoffg.net |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
Morning Geoff No, no timers at all running. It is a mystery and definitely associated with the CFunction - if I REM it out, the problem doesn't manifest. I was checking for shorts and all sorts but it just made no sense. Maybe the HEX got corrupted when I copied it across or something. In the end I etched a tiny 3-channel level-shifter (2 resistors and a FET per channel, all SMD so postage stamp sized board) which I "dead-bugged" onto the PCB and cut the tracks with appropriate back-wiring so I could use the hardware SPI port - all working and with the customer for testing. Version 0.1 A mystery which I will visit again, but I just ran out of time... as usual. Thanks |
||||
led-bloon Senior Member Joined: 21/12/2014 Location: AustraliaPosts: 202 |
Try: Remove the "OC" in -"Pin(CS)=1:SetPin CS,DOUT,OC" and the rest of the pins for SPI2 as well. led Miss you George |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
Hi 'bloon I will replicate things another time, the board is with the customer now. It is a mystery but your idea is a good one to see if that low can be "driven" into. I will add it to the list. I want to get this working as SPI on any pin is a really nice to have. Never used the embedded function before... have used the serial routines lots of times. SPI (and serial) as protocols are about as simple as it gets - especially one way. I have bashed them in assembler a few times over the years. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3649 |
Could it be the CFunction (CSub) that is keeping the pin going? (I'm guessing it can still be active even back at the command prompt.) John |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
Evening John. That was my guess too - it needs a power cycle to stop it i.e. once started I have no control (prolly a CPU RESTART would fix as well but dint try). It is not expected behaviour and from code that is quite old (= mature)... Geoff says it has been tested extensively and that is good enough for me. I am wondering if I missed a bit off the HEX when I copied the routine from the PDF or something. I have had odd instances of weird stuff happening in the past that was fixed by re-flashing, but everything else about this uM is spot on - it doesn't have that "feel" of a corrupt firmware. A proper mystery that I am keen to get my teeth into - I will build up a test rig when it gets a bit quieter (never been busier, got four projects going out of the workshop this week) but for now I modded the PCB to use the hardware SPI... all working and on test with the customer. h |
||||
Print this page |