BlueMagic
BlueMagic copied to clipboard
[Idea] Use open drain mode to directly talk to 1.8V logic
https://github.com/konsgn/BlueMagic/blob/e9f1c3a4243a2a7ab5aaef2a7d7afad281c1c389/csrspi.c#L72
Change GPIO_CNF_OUTPUT_PUSHPULL to GPIO_CNF_OUTPUT_OPENDRAIN, in this mode the STM32 pins won't output any voltage when the pin is "1".
Connect CS, CLK, MOSI and MISO directly to the bluetooth chip.
Add 470 Ohm resistors in CS, CLK and MOSI (Not required for MISO) connected between the signal and 1.8V.
Tested, works wonders and reduces the hardware requirements to the minimum.
Also, this seems to speed things up: https://github.com/konsgn/BlueMagic/blob/e9f1c3a4243a2a7ab5aaef2a7d7afad281c1c389/csrspi.c#L132-L140
GPIOPinWrite(CSR_PORT_BASE, PIN_CLK | PIN_MOSI, (nData & 0x800000) ? PIN_MOSI : 0);
CsrSpiDelay();
GPIOPinWrite(CSR_PORT_BASE, PIN_CLK, PIN_CLK);
CsrSpiDelay();
nData <<= 1;