uint16_t spi_send_uint8_receive_13bits(uint8_t to_send) { spi_prepare_txrx_bits(8, 13); *spi_fifo = to_send; spi_start_tx(); spi_wait_ready(); return (*spi_fifo) & 0x1FFF; }
void spi_send_data(const uint8_t * data, uint8_t datasize) { uint32_t *_data = (uint32_t*)data; uint8_t i; uint8_t words_to_send = __min((datasize + 3) / 4, SPIFIFOSIZE); spi_prepare_tx(datasize); for(i = 0; i < words_to_send;i++) spi_fifo[i] = _data[i]; spi_start_tx(); }
void spi_send_uint16_r(uint16_t data, int32_t repeats) { uint32_t i; uint32_t word = data << 16 | data; while(repeats > 0) { uint16_t bytes_to_transfer = __min(repeats * sizeof(uint16_t) , SPIFIFOSIZE * sizeof(uint32_t)); spi_wait_ready(); spi_prepare_tx(bytes_to_transfer); for(i = 0; i < (bytes_to_transfer + 3) / 4;i++) spi_fifo[i] = word; spi_start_tx(); repeats -= bytes_to_transfer / 2; } }
uint8_t sd_cmd0() { int i, r; spi_start_tx(sd_spi); for(i = 0; i < 10; i++) spi_rxtx(sd_spi, 0xFF); spi_rxtx(sd_spi, 0x40); spi_rxtx(sd_spi, 0x00); spi_rxtx(sd_spi, 0x00); spi_rxtx(sd_spi, 0x00); spi_rxtx(sd_spi, 0x95); //Polling it to check response to 0x01 r = 0xFF; for(int i = 0; i < 1000 && r != 0xFF; i++) r = spi_rxtx(sd_spi, 0xFF); return r; }