//////////////////////////////////////////////////////////// // Read the contents of the register at <address> //////////////////////////////////////////////////////////// char can_read_reg(char address){ spi_init_buffer(); // Read command spi_load_byte(c2515Read); // Register address spi_load_byte(address); // Expect one byte answer spi_load_zeros(0x01); // Start the transfer spi_exchange(); spi_wait_for_completion(); return spi_get_byte(2); }
//////////////////////////////////////////////////////////// // Read several bytes from the other device into the // data buffer. Used when you're talking through a // one-wire SPI interface (e.g. for nRF2401). // ! The data output pin should be disabled when this // ! routine is called. //////////////////////////////////////////////////////////// void spi_read(char nr_of_bytes){ // Buffer init spi_init_buffer(); // Set the number of bytes we want to read spi_load_zeros(nr_of_bytes); // Disable the output pin //spi_do_tris = 1; // Do the exchange spi_exchange(); // Wait for completion spi_wait_for_completion(); // Enable the output pin again //spi_do_tris = 0; return; }