reset an spi connection? pb with max7219 #5998
Replies: 1 comment
-
Posted at 2018-09-16 by Mrbbp i have a long text to display, so i've subdivised text by piece of 10 chars to reduce mem usage and time to drawString in the arrayBuffer... (code look complexe and not optimised) Posted at 2018-09-16 by @allObjects I did not completely see thru your code, but mainly, there is a heave function and a much lighter function, each independent of each other and called on individual intervals. What is going on here is to understand from the point of how Espruino works, or in other words, how event driven JavaScript environment works. First, though, let's look at the code - especially at the on init: Every 60 ms, sendData() is invoked, If you put console.log into your code, you will see that 5 or 6 times led() runs before sendData() is run the first time. Also, when you put console.log at begin and end as first and last in led() and sendData(), you will notice that one always runs completely before it runs again or something else runs (completely). To make it bette visible, change the time to a least the 10 fold: 600 and 100 ms, that way Espruino can - most of the time - take care of what it is told to do before a new time event happens and the same ore something else should happen. JavaScript is executed as single thread. No things will go in parallel at any time. A time event (or event through a sensor on a pin from outside) create an even/interrupt in the event/interrupt queue in the primary or hardware run cycle. It is called primary because it is closest to the hardware - pin change, timer event - overrun/underrun/0-crossing) - happens and has higher priority then JavaScript execution. When all these high prioritized events/interrupts have been served and respective event with its data/context package is written to the JavaScript event/interrupt queue, the primary cycle goes into idle... but the processor is now free to take care of the events that were put into the JavaScript event queue. The processor 'starts'/resumes the work of interpreting JavaScript: for each entry in the JavaScript is invoked. In your case, led()... and led() again, etc. until sendData() is encountered and worked on. Now it may be that it cannot finish that within 10ms, so led() has and does wait until the processor gets free again for pickup. Even though both of your functions called at intervals have nothing to do with each other, they can have an impact on each other. Do you know how much time it take to execute sendData()? Adding getTime() at begin and end with delta calculation will tell you., You may see the effect of the internal JavaScript Event Queue to overflow, even though it is decently sized to handle bursts, but continuous pounding. Posted at 2018-09-16 by Mrbbp Hello @allObjects, Posted at 2018-09-17 by Mrbbp @allObjects why do you think it is a transcription from another langage? I've rewrote with a setTimeout. Posted at 2018-09-17 by @allObjects
The loop puzzled me and also the double setInterval(). ...but as you noticed, I had withdrawn it right after initial/partial post. NM. If you restart a function at the end with a setTimeout() (with a time dependent, calculated/variable) tiemout time), you are fine, because this gives the system time to answer things that may have queued up. Chopping up bit work helps in that respect. Regarding spi transfer being asynchronous, I'm not sure. I assume that it is some what and when it is, it still has a buffer that may overflow... It is for sure implemented natively - not in JS - in order to act timely, especially when it is soft spi. Being natively implemented and considerate of the Espruino context, I expect it on higher priority - can interrupt JS process - but is 'knows' what JS can do to the system and behaves accordingly (managing variables, buffer, etc). Posted at 2018-09-18 by Mrbbp So the problem persist, time to time... I suppose spi is asynchronous... Thanks for your help. Posted at 2018-09-18 by @gfwilliams Is it possible that it's actually to do with wiring? Do you have GND properly connected between the controller and the MAX7219? Or how long are the wires you're using? An 8x8 LED matrix at 5v can draw a lot of power, so with long, thin wires the voltage drop can be enough that you get communications issues. You can easily change the baud rate if needed though: http://www.espruino.com/Reference#l_SPI_setup |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-16 by Mrbbp
Hello, i'm working with a cheap chinese 8x8 led matrix mounted with a Max7219.
sometime ( i'm enable to determine when or why, can't reproduce bug). the display go weird... it show only one line or 2 lines of pix... after a time it come back good.
if i unplug/replug the board (a pico) everything restart well.
in first i was thinking about a prob with the graphic buffer but when i ask to show content it look full of datas...
therfore i was thinking a prob with the display...
is it possible to reduce the spi baudrate and in wich value?
or to reset an spi connection?
do i need to find an other matrix with better chip... an idea?
ps: i'm testing with low data transfer to display and it seem to work well (show on display one time on 10)
i'have a second timer with a led pulse...
regards
Beta Was this translation helpful? Give feedback.
All reactions