Sharing SPI bus with APA102 & n other peripherals ( faking an 'APA102 CS' pin ) #1013
Replies: 9 comments
-
Posted at 2019-01-28 by @gfwilliams Yes, you could probably do something like that - but how about dynamically swapping SPI/I2C to some of the other pins the device can output, or just using software SPI/I2C? Software SPI particularly is actually quite fast. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-30 by stephaneAG All right, I'll have to test it & come back with the results ;) If I understand you correctly, your suggestions ( software spi or pin swapping ) won't help reduce the number of pins used, right ? Or by 'pins swapping', do you mean declaring software or hardware spi/i2c but with a different pin for the clock signal so as to only have the device(s) with this clock pin connected to actually received data ? See the attached image for the list of pins I need to connect everything to the Espruino Wifi To "optimize" the pins mapping ( and at least get below 21 ;) ), I was thinking of a way to free 3 pins while still allowing the use of 'setWatch()' for the 5-way switch, but this may or not work at all depending on if I can manage to get just the right resistor values AND have the transistor go saturated for every button ( maybe by wiring it's base to each button output, not only the last one ? .. ) I'm thinking of another way to doing so but didn't take the time to write them down or have a try on them ( .. ) Can wait to have everything fit on the EspruinoWifi pins in one way or another & hope my program fits in the memory before finally trying this project .. finger's crossed :) ' be posting updates on the spi/i2c APA thing & the 5-way switch as soon as can do ;)Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-30 by stephaneAG I just tested something like http://www.reuk.co.uk/wordpress/wp-content/uploads/2013/09/selector-switch-resistor-ladder-adc.jpg, but:
I'm using the following code for my tests:
I guess I'll have to be more cautious on the length of the wires used between uC & the resistors to have something ~constant in this circuit, hoping the erroneous readings come from that .. ---- update ----
Hoping to have a clearer view of the troubles in the morning ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-30 by @gfwilliams
I hadn't really considered that, but yes, that would work great. For the SD card you have a chip select pin so that might give you something you can use as well?
Sounds like a good plan with the resistors + analog. I'd say don't use an internal pulldown as it won't work with analogRead (iirc), and make sure that when pressed the voltage changes from 0v to above 1.7v to make sure you get a reliable setWatch. Also remember that to get And to get reliable analog readings you may want a (small) capacitor between GND and A0. You may also be able to put the battery charge status and/or toggle switch on exactly the same A0 pin as well. If your 5 voltages are 2v,2.25v,2.5v,2.75v and 3v then if the toggle switch varied the voltage by 0.05v you could detect that. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-31 by stephaneAG Hi there !
Actually, I thought about it when reading your suggestion ;p
Indeed: it also gives me a ( silly ? ) idea: using the SDCARD SPI CS pin as the pin on which to set the APA102 SPI CLK () so that the APA102 CLK 'll be tied low while the SD card is in use ? ( so by writing to the SD, it shall auto-disable the APA102 comm ? I guess it'd be even better than tying the SD CS pin to Gnd & then doing the above 'different pin for the clock signal' hack ? ) Onto the "2pins analog setWatch" hack, I had some success with a quite simple circuit in which the A0 pin ( on which a digital setWatch() is set ) is connected directly to the A1 pin, used as analog input.
I'm not sure yet if my setup is precise enought & on how to implement that ( for either the batt. status pin, the toggle, or both ? .. - I plan to use the MCP73831 's stat pin as battery status pin, for info .. ) Now, the voltages I currently get ( from the resistor values I could find around easily ) are the ones in the following code, I'm currently happy with those ( seems to work flawlessly ), but if anyone has hints on better resistor values, I'm a taker ;) nb: I'm not quite sure of the followings ( gotten using successive tries on tinkercad .. ), but these may be the resistor values you had in mind to produe your proposed voltages ? So, here's some wip working code :)
This being said, I'm onto drawing a little "delayed power off" circuit that may be useful to get on one ( not shared ) pin as well ;) Thanks for the precious hints :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-31 by @gfwilliams
The ADC in the chip expects quite a low resistance to get accurate results (since otherwise the act of switching in the ADC itself would cause the voltage to drop) - so the capacitor gives you that low resistance :) It may not actually be an issue here at all - it's usually for 100k+, and you're not looking to get loads of accuracy (I guess even just 6 bits would do you pretty well). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-02-01 by stephaneAG Hi I just tried with different "small" caps ( 1pF, 100nF, 1uF ), yet it seems I don't get any changes in the output ( as without, *3.3, I get "X.YZnnnn" where X & Y are constant, Z seems to be +/- 1 & n's are not constant whatsoever .. ) -> I'm currently finishing the "delayed power off" thing, posting it right after it's done & then onto testing those SPI sharedp ins hacks ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-02-01 by stephaneAG So ! Now, to be able to use the above circuit, I'll need 2 pins .. so I better go trying the "shared SPI pins" before planning on doing so ;pAttachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-02-04 by @gfwilliams Does it matter about voltage drop across D1? As soon as the microcontroller is powered on it can turn Q1 on, which will remove the voltage drop anyway? But I'd just use a schottky diode? About 0.3v voltage drop? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-27 by stephaneAG
Hi !
To increase the number of available pins on the Espruino Wifi ofr a current project, I wish to share the I2C & SPI bus for several peripherals:
On the I2C side:
On the SPI side:
I had a quick thnk on 'may-be solutions', but I'd be glad receiving further advices before not knowingly messing around
The following drawing is for the SPI side of things, but I wonder if fiddling with the I2C CLK would lead to same behavior ?
Thanks in advance :)
++
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions