Suggestion for MAX7219 library (and others ?)

5 views
Skip to first unread message

pinhe...@gmail.com

unread,
Nov 1, 2022, 12:29:47 PM11/1/22
to jallib
Hi guys,

I ran into a problem with a program using the MAX7219_1 library.
It appeared that I made some calls to communicate with the MAX as well in my main program and in interrupt routines.
Problem was that when interrupts occured during the write to the MAX, and then the interrupt routine tries also to start a communication with the MAX, the result was unexpected.

The solution is, of course, to disable the INTCON_GIE in my main program before accessing the MAX and reactivate it afterwards, which I have done, and it works pretty well

I was wondering if this couldn't be achieved in the MAX7219 library itself in the same way that it is done to prevent de data_hef_write to crash:
- Save the present state of INTCON_GIE
- Put INTCON_GIE to False
- Execute the communication to the MAX
- Set INTCON_GIE with the saved state.

Note that my problem occured as well when using SPI_hardware (my prefered choice since I am using a PIC16F1705) as with the SPI_software

What do you think of this idea ?
This could also be extended to other libraries where such communication with external devices occurs (SPI, I2C, ....)

Enjoy your evening,

David

Rob CJ

unread,
Nov 1, 2022, 1:51:54 PM11/1/22
to jallib
Hi David,

My personal opinion is that a library should  only disable interrupts when is it a must for the library. If you disable an interrupt in a library and there is some time needed for processing, you may disturb the main program because the user is unaware of it.

For the HEF the datasheet describes that you must disable all interrrupts to prevent corruption of the data. Processing time is very short in this case.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens pinhe...@gmail.com <pinhe...@gmail.com>
Verzonden: dinsdag 1 november 2022 17:29
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] Suggestion for MAX7219 library (and others ?)
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/6b7e3091-0689-4179-9cd2-d7983ccdb88en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages