Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * \ingroup sd_raw
- * Sends a raw byte to the memory card.
- *
- * \param[in] b The byte to sent.
- * \see sd_raw_rec_byte
- */
- void sd_raw_send_byte(uint8_t b)
- {
- SPDR = b;
- /* wait for byte to be shifted out */
- while(!(SPSR & (1 << SPIF)));
- SPSR &= ~(1 << SPIF);
- }
- /* FORCE ERASE */
- uint8_t send_cmd42_erase(){
- uint8_t response,i;
- uint8_t arg = 0x08;
- uint8_t command = 0x2a;
- uint16_t crc = calc_crc(mess,((command&arg)|command),CRC16STARTBIT);
- /* wait some clock cycles */
- sd_raw_rec_byte();
- Serial.print("Starting erase procedure");
- select_card(); // select SD card first
- sd_raw_send_byte(0x40 | 0x10);
- sd_raw_send_byte(0x01 & 0xff);
- sd_raw_send_byte(0x40 | 0x2a);
- sd_raw_send_byte((arg >> 0) & 0xff);
- /*CRC16 CCITT*/
- //CRC16 is calculated over data given/sent (block length*n_frames_sent)
- //SPI does not force CRC checking, but i'll enable it anyway
- //CRC16=size(command+argument) (38 bits)
- sd_raw_send_byte((crc >> 8) & 0xff);
- sd_raw_send_byte((crc >> 0) & 0xff);
- /* receive response */
- for(i = 0; i < 10; ++i)
- {
- response = sd_raw_rec_byte();
- if(response != 0xff)
- break;
- }
- return response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement