SukkoPera / PsxNewLib

Playstation controller interface library for Arduino
GNU General Public License v3.0
133 stars 29 forks source link

Hardware SPI on Leonardo #12

Closed sonik-br closed 2 years ago

sonik-br commented 3 years ago

Hi! I'm trying to use the hardware ICSP pins on the Leonardo with the PsxControllerHwSpi lib. No success ... I'm doing: PSX > Leonardo ICSP pin DAT > 1 (MISO) CLK > 3 (SCK) CMD > 4 (MOSI) ATT > 9 (digital pin, not on ICSP) Also GND and 3.3V...

It's supposed to work on the Leonardo or just on the Uno?

SukkoPera commented 3 years ago

It works great on the Leonardo, make sure to use the right pins and 1k pullups.

Also make sure to use the right pin for ATT. I think it's 10 by default, switch pin or change it in the sketch.

sonik-br commented 3 years ago

1k pullups in which pins? I'm not good with electronics XD

SukkoPera commented 3 years ago

On DAT/MISO at least.

SukkoPera commented 3 years ago

image

This is the correct way to do the connections by the way.

sonik-br commented 3 years ago

No luck :( Even with the 1k pullups on the MISO pin.

I'm powering the psx controller with 3.3v from the arduino. But all other pins are 5v. This might be the problem?

SukkoPera commented 3 years ago

Well, if all the other pins are 5V you're not driving the controller properly. I know everybody out there does that but it doesn't make me happy. Try powering the controller at 5V too, but do so at your risk. The 3v3 regulator might not be able to provide enough current.

I'd send you one of my PsxShields to thank you for the collaboration but I see you live in Brazil, which I had a lot of problems shipping to :(.

sonik-br commented 3 years ago

Thanks but yeah, postal services here are not reliable.

Something like this would work for the data pins? https://www.amazon.com/HiLetgo-Channels-Converter-Bi-Directional-3-3V-5V/dp/B07F7W91LC/

I can get some here at the local electronics store for a good price. And it seems foolproof to me :) The schematic: https://s3-sa-east-1.amazonaws.com/robocore-lojavirtual/522/Level.Shifter_v1.1.pdf

SukkoPera commented 3 years ago

Well, it's the same shifting technique I've used on my shield: image

As you can see, I have changed the pull-ups to 1k, after measuring a real PSX console. This gave me some more compatibility, but most controllers were also working with 10k.

Besides that, you'd also need a beefier 3.3V regulator. I'm not sure how much current the PSX controller needs, but the 3v3 regulator on most Arduinos is really really weak.

Can you solder SMD stuff?

sonik-br commented 3 years ago

No, I can't do SMD stuff. Controller (guncon) works fine using "bitbang" with 3.3v power and 5v on data pins. Serial must be more sensitive to voltage level?

EDIT: This could be used for the regulator? AMS1117 image

SukkoPera commented 3 years ago

Not really, SPI should be more reliable, actually. What do you get if you enable debugging?

I will try sending you a shield, please send me your address by email. I will solder the SMD stuff for you but I have run out of the long pin headers, will you be able to get those yourself and solder them?

Yes, that regulator will be fine.

sonik-br commented 3 years ago

Thanks :)

I tested with the DumpButtonsHwSpi example and it wont send anything to the serial debug. With DUMP_COMMS on PsxNewLib.h it was sending some info to the serial. I will have to run it again and copy the results here.

I will also do a quick test with the correct regulator and level shift.

SukkoPera commented 3 years ago

That is very weird, you should get some output even if you don't connect your controller... I think. It's been a while since I worked on this lib.

Let me know what shows up with DUMP_COMMS.

sonik-br commented 3 years ago

I was testing it right now... properly wired with 3.3v level shift and regulator. Log starts with no controller connected. It shows various connect/disconnect. But it was connected all the time.

Serial LOG.txt

sonik-br commented 3 years ago

Done a quick test with DumpButtonsBitBang but this time using the SPI pins. Won't work. From my understanding the dedicated pins should work as common digital I/O pins. Starting to think I have a bad board.

SukkoPera commented 3 years ago

Yep, it should work if you use the following pin numbers:

#define PIN_SPI_MOSI  (16)
#define PIN_SPI_MISO  (14)
#define PIN_SPI_SCK   (15)

MOSI goes to CMD and MISO to DAT.

sonik-br commented 3 years ago

Great news! Got another level shifter and now it works! 3.3v on power and data pins to the guncon and using hardware SPI. Now my other guncon (a thirdy party one) seems to work. It was not even detecting previously when using bitbang. I will wait for the shield to arrive to test it more.