Skip to content

Instantly share code, notes, and snippets.

@eely22
Last active August 29, 2015 14:07
Show Gist options
  • Save eely22/2bedc0ce3f7e2251174d to your computer and use it in GitHub Desktop.
Save eely22/2bedc0ce3f7e2251174d to your computer and use it in GitHub Desktop.
static uint8_t tx_data[1]; /**< SPI TX buffer. */
static uint8_t rx_data[1]; /**< SPI RX buffer. */
static uint8_t id[3]; /**< SPI RX buffer. */
/**@brief Function for application main entry.
*/
int main(void)
{
//connect
spi_base_address = spi_master_init(SFLASH_SPI, SPI_MODE0, (bool)0);
//send the 'get id' code
tx_data[0] = 0x9f;
rx_data[0] = 0x0;
spi_master_tx_rx(spi_base_address, 1, (const uint8_t *)tx_data, rx_data);
//read the first byte back
tx_data[0] = 0xff;
rx_data[0] = 0x0;
spi_master_tx_rx(spi_base_address, 1, (const uint8_t *)tx_data, rx_data);
id[0] = rx_data[0];
//read the second byte back
tx_data[0] = 0xff;
rx_data[0] = 0x0;
spi_master_tx_rx(spi_base_address, 1, (const uint8_t *)tx_data, rx_data);
id[1] = rx_data[0];
//read the third byte back
tx_data[0] = 0xff;
rx_data[0] = 0x0;
spi_master_tx_rx(spi_base_address, 1, (const uint8_t *)tx_data, rx_data);
id[2] = rx_data[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment