Last active
November 4, 2021 02:47
-
-
Save DaelonSuzuka/1c43cdc5f76beadaf6fdd52c73c39c13 to your computer and use it in GitHub Desktop.
SPI bitbang driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdint.h" | |
/* ************************************************************************** */ | |
#define set_STROBE_PIN(state) LATXbits.LATXY = state // your register here | |
#define set_CLOCK_PIN(state) LATXbits.LATXY = state // your register here | |
#define set_DATA_PIN(state) LATXbits.LATXY = state // your register here | |
static void spi_bitbang_tx_word(uint16_t word) { | |
set_STROBE_PIN(1); | |
set_CLOCK_PIN(0); | |
for (uint8_t i = 0; i < 16; i++) { | |
if (word & (1 << (15 - i))) { | |
set_DATA_PIN(1); | |
} else { | |
set_DATA_PIN(0); | |
} | |
delay_us(10); | |
set_CLOCK_PIN(1); | |
delay_us(10); | |
set_CLOCK_PIN(0); | |
delay_us(10); | |
} | |
set_STROBE_PIN(0); | |
delay_us(10); | |
set_STROBE_PIN(1); | |
delay_us(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment