I’m using PRU0 on PocketBeagle and want to implement SPI via bit-banging in C (not using DTS or ARM). I need to toggle SCLK, CS, and read MISO manually. Can someone share a minimal working example or guide?
What device are you trying to control? Below is a project to control the ILI9341 displays from a BBB. I don’t have a pocketbeagle, you’d have to port the pin assignments. If you have a BBB, i suggest that use it to study my implementation before dealing with the port to the pocketbeagle.
https://forum.beagleboard.org/t/turnkey-pru-deskclock-application-for-bbb/34126
this project does what you are looking for. it manipulates sclk, mosi (NOT MISO), DC and CS via symbolic substitution which makes the app level ASM readable. you can download the disk image and run from a uSD card … the project can be recompiled from source for easy modification.
would be interested in your progress, good luck
gomer
It is simple, you define gpio, here it is on a RL78, the idea is to se the bits to 0 or 1 in the correct order
You check to see if the order of the bits is LSB or MSB
You can use a scope to check the length of the delay, count the cycle
The smaller the delay the faster the date
void SendCommand(uint8_t Command)
{
uint8_t Num;
LCD_CS = 0; // Select LCD
LCD_A0 = 0; // Select LCD Command
for (Num = 0; Num < 8; Num++)
{
LCD_SCK = 0;
if (Command & 0x80)
{
LCD_SO = 1;
}
else
{
LCD_SO = 0;
}
Delay();
LCD_SCK = 1;
Command <<= 1;
}
LCD_CS = 1; // Deselect LCD
}
void SendData(uint8_t Data)
{
uint8_t Num;
LCD_CS = 0; // Select LCD
LCD_A0 = 1; // Select LCD data
for (Num = 0; Num < 8; Num++)
{
LCD_SCK = 0;
if (Data & 0x80)
{
LCD_SO = 1;
}
else
{
LCD_SO = 0;
}
Delay();
LCD_SCK = 1;
Data <<= 1;
}
LCD_CS = 1; // Deselect LCD
}