Пример #1
0
void spi_init( void) {
    /* Set MOSI and SCK output, all others input */
    SPI_DDR |= _BV(SPI_MOSI_PIN)| _BV(SPI_SCK_PIN);

    /* enable pull up for miso */
    //  SPI_PORT |= _BV(SPI_MISO_PIN);

    /* Set SS0 output */
    sbi( SPI_SS0_DDR, SPI_SS0_PIN);
    /* SS0 idles high (don't select slave yet)*/
    SPI_UNSELECT_SLAVE0();

    /* Set SS1 output */
    sbi( SPI_SS1_DDR, SPI_SS1_PIN);
    /* SS1 idles high (don't select slave yet)*/
    SPI_UNSELECT_SLAVE1();

    spi_cur_slave = SPI_NONE;
}
Пример #2
0
void ad7714_on_spi_it( void ) {
  uint8_t spi_read = SPDR;
  if (msg == &ad7714_read) {
    if (idx==1)
      ad7714_sample = spi_read<<8;
    else if (idx==2) {
      ad7714_sample += spi_read;
      ad7714_sample_read = TRUE;
    }
  }
  idx++;
  if (idx < msg->len) {
    SPI_SEND(msg->data[idx]);
  }
  else {
    SPI_UNSELECT_SLAVE1();
    SPI_STOP();
  }
}