Exemplo n.º 1
0
// Power On Reset as described in  19.1.2 of cc1100 datasheet, tried APOR as described in 19.1.1 but that did not work :-(
void ccx_power_on_startup()
{
	//SPICLK=CPU/64
	spi_init(_BV(SPR1) | _BV(SPR0));

  // start manual Power On Reset 
  spi_slave_select(HIGH);
  _delay_us(1);
  
  spi_slave_select(LOW);
  _delay_us(10);
  
  spi_slave_select(HIGH);
  _delay_us(41);
  
  spi_slave_select(LOW);
  
  // wait for MISO to go low
  while(MISO_STATE);
  
  spi_transfer(CCx_SRES);
 
//  printf("Waiting for CCx to complete POR\n");

  // wait for MISO to go low
  while(MISO_STATE);
  
  spi_slave_select(HIGH);
  
//  printf("CCx POR complete\n");
}
Exemplo n.º 2
0
uint8_t ccx_strobe(uint8_t addr)
{
  uint8_t result;

  spi_slave_select(LOW);
  // wait for MISO to go low
  while(MISO_STATE);
  
  result = spi_transfer(addr);
//printf("S %02x\n", addr);
  
  spi_slave_select(HIGH);
  
  return result;
}
Exemplo n.º 3
0
uint8_t ccx_read(uint8_t addr, uint8_t *data)
{
  uint8_t result;
  
  spi_slave_select(LOW);
  // wait for MISO to go low
  while(MISO_STATE);
  
  result = spi_transfer(addr | 0x80);
  *data = spi_transfer(0);

  spi_slave_select(HIGH);
//printf("R: %02x %02x %02x\n", addr, result, *data);

  return result;
}
Exemplo n.º 4
0
void m25_write_status(u8 sr)
{
  spi_slave_select(SPI_SLAVE_FLASH);
  spi_xfer(SPI_BUS_FLASH, M25_WRSR);
  spi_xfer(SPI_BUS_FLASH, sr);
  spi_slave_deselect();
}
Exemplo n.º 5
0
uint8_t ccx_write(uint8_t addr, uint8_t dat)
{
  uint8_t result;
  
  spi_slave_select(LOW);
//printf("W: %02x %02x\n\r", addr, dat);
  // wait for MISO to go low
  while(MISO_STATE);
  
  result = spi_transfer(addr);
  result = spi_transfer(dat);

  spi_slave_select(HIGH);
  
  return result;
}
Exemplo n.º 6
0
void main(void)
{
    struct spi_config config = { 0 };
    struct device *spi_mst_0 = device_get_binding("SPI_0");
    uint8_t id;
    int err;

    printk("SPI Example application\n");

    if (!spi_mst_0)
        return;

    config.config = SPI_MODE_CPOL | SPI_MODE_CPHA | SPI_WORD(16);
    config.max_sys_freq = 256;

    err = spi_configure(spi_mst_0, &config);
    if (err) {
        printk("Could not configure SPI device\n");
        return;
    }

    err = spi_slave_select(spi_mst_0, 1);
    if (err) {
        printk("Could not select SPI slave\n");
        return;
    }

    id = lsm9ds0_read_whoami_g(spi_mst_0);

    printk("LSM9DS0 Who Am I: 0x%x\n", id);
}
Exemplo n.º 7
0
/* Returns the 32-bit value representing temperature data from the module. */
static uint32_t max31855_read(void)
{
    uint32_t raw_reading;

    spi_slave_select(SPI_SLAVE_MAX31855);
    raw_reading = spi_read_dword();
    spi_slave_deselect();
    return raw_reading;
}
Exemplo n.º 8
0
u8 m25_read_status(void)
{
  u8 sr;

  spi_slave_select(SPI_SLAVE_FLASH);
  spi_xfer(SPI_BUS_FLASH, M25_RDSR);
  sr = spi_xfer(SPI_BUS_FLASH, 0x00);
  spi_slave_deselect();
  return sr;
}
Exemplo n.º 9
0
uint8_t ccx_read_burst(uint8_t addr, uint8_t *dataPtr, uint8_t size)
{
  uint8_t result;
  
  spi_slave_select(LOW);
  // wait for MISO to go low
  while(MISO_STATE);
  
  result = spi_transfer(addr | 0xc0);

  while(size) {
    *dataPtr++ = spi_transfer(0);
    size--;
  }
  
  spi_slave_select(HIGH);
  
  return result;
}
Exemplo n.º 10
0
void m25_bulk_erase(void)
{
  spi_slave_select(SPI_SLAVE_FLASH);

  spi_xfer(SPI_BUS_FLASH, M25_BE);

  spi_slave_deselect();

  while(m25_read_status() & M25_SR_WIP);
}
Exemplo n.º 11
0
/** Write to one of the MAX2769 registers.
 *
 * \param addr MAX2769 register to write to.
 * \param data Data to write to register (28 bits).
 */
void max2769_write(u8 addr, u32 data)
{
  u32 write_word = ((data << 4) & 0xFFFFFFF0) | (addr & 0x0F);

  spi_slave_select(SPI_SLAVE_FRONTEND);
  spi_xfer(SPI_BUS_FRONTEND, (write_word >> 24) & 0xFF);
  spi_xfer(SPI_BUS_FRONTEND, (write_word >> 16) & 0xFF);
  spi_xfer(SPI_BUS_FRONTEND, (write_word >>  8) & 0xFF);
  spi_xfer(SPI_BUS_FRONTEND, (write_word >>  0) & 0xFF);
  spi_slave_deselect();
}
Exemplo n.º 12
0
uint8_t ccx_write_burst(uint8_t addr, const uint8_t* dataPtr, uint8_t size)
{
  uint8_t result;
  
  spi_slave_select(LOW);
  // wait for MISO to go low
  while(MISO_STATE);
  
  result = spi_transfer(addr | 0x40);

  while(size)
  {
    result = spi_transfer(*dataPtr++);
    size--;
  }
  
  spi_slave_select(HIGH);
  
  return result;
}
Exemplo n.º 13
0
bool _cc2520_write_reg(struct cc2520_spi *spi, bool freg,
		       uint8_t addr, uint8_t value)
{
	spi->cmd_buf[0] = freg ? CC2520_INS_MEMWR : CC2520_INS_REGWR;
	spi->cmd_buf[1] = addr;
	spi->cmd_buf[2] = value;

	spi_slave_select(spi->dev, spi->slave);

	return (spi_write(spi->dev, spi->cmd_buf, 3) == 0);
}
Exemplo n.º 14
0
static int ti_adc108s102_read(struct device *dev,
					struct adc_seq_table *seq_table)
{
	struct ti_adc108s102_config *config = dev->config->config_info;
	struct ti_adc108s102_data *adc = dev->driver_data;
	struct spi_config spi_conf;
	uint32_t data[2] = {0, 0};
	struct nano_timer timer;
	int ret = 0;
	int32_t delay;

	spi_conf.config = config->spi_config_flags;
	spi_conf.max_sys_freq = config->spi_freq;

	nano_timer_init(&timer, data);

	if (spi_configure(adc->spi, &spi_conf)) {
		return -EIO;
	}

	if (spi_slave_select(adc->spi, config->spi_slave)) {
		return -EIO;
	}

	/* Resetting all internal channel data */
	memset(adc->chans, 0, ADC108S102_CHANNELS_SIZE);

	if (_verify_entries(seq_table) == 0) {
		return -EINVAL;
	}

	adc->seq_table = seq_table;

	/* Sampling */
	while (1) {
		delay = _ti_adc108s102_prepare(dev);
		if (delay == ADC108S102_DONE) {
			break;
		}

		nano_timer_start(&timer, delay);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);

		ret = _ti_adc108s102_sampling(dev);
		if (ret != 0) {
			break;
		}

		_ti_adc108s102_handle_result(dev);
	}

	return ret;
}
Exemplo n.º 15
0
u32 m25_read_id(void)
{
  u8 manf_id, mem_type, mem_capacity;

  spi_slave_select(SPI_SLAVE_FLASH);
  spi_xfer(SPI_BUS_FLASH, M25_RDID);
  manf_id = (u8)spi_xfer(SPI_BUS_FLASH, 0x00);
  mem_type = (u8)spi_xfer(SPI_BUS_FLASH, 0x00);
  mem_capacity = (u8)spi_xfer(SPI_BUS_FLASH, 0x00);
  spi_slave_deselect();

  return mem_capacity | mem_type << 8 | manf_id << 16;
}
Exemplo n.º 16
0
void m25_sector_erase(u32 addr)
{
  spi_slave_select(SPI_SLAVE_FLASH);

  spi_xfer(SPI_BUS_FLASH, M25_SE);

  spi_xfer(SPI_BUS_FLASH, (addr >> 16) & 0xFF);
  spi_xfer(SPI_BUS_FLASH, (addr >> 8) & 0xFF);
  spi_xfer(SPI_BUS_FLASH, addr & 0xFF);

  spi_slave_deselect();

  while(m25_read_status() & M25_SR_WIP);
}
Exemplo n.º 17
0
uint8_t _cc2520_read_reg(struct cc2520_spi *spi,
			 bool freg, uint8_t addr)
{
	spi->cmd_buf[0] = freg ? CC2520_INS_MEMRD : CC2520_INS_REGRD;
	spi->cmd_buf[1] = addr;
	spi->cmd_buf[2] = 0;

	spi_slave_select(spi->dev, spi->slave);

	if (spi_transceive(spi->dev, spi->cmd_buf, 3,
			   spi->cmd_buf, 3) == 0) {
		return spi->cmd_buf[2];
	}

	return 0;
}
Exemplo n.º 18
0
void m25_page_program(u32 addr, u8 len, u8 buff[])
{
  u32 i;

  spi_slave_select(SPI_SLAVE_FLASH);

  spi_xfer(SPI_BUS_FLASH, M25_PP);

  spi_xfer(SPI_BUS_FLASH, (addr >> 16) & 0xFF);
  spi_xfer(SPI_BUS_FLASH, (addr >> 8) & 0xFF);
  spi_xfer(SPI_BUS_FLASH, addr & 0xFF);

  for(i = 0; i < len; i++)
    spi_xfer(SPI_BUS_FLASH, buff[i]);

  spi_slave_deselect();

  while(m25_read_status() & M25_SR_WIP);
}
Exemplo n.º 19
0
void m25_read(u32 addr, u32 len, u8 *buff)
{
  spi_slave_select(SPI_SLAVE_FLASH);

//  spi_xfer(SPI_BUS_FLASH, M25_FAST_READ);
  spi_xfer(SPI_BUS_FLASH, M25_READ);

  spi_xfer(SPI_BUS_FLASH, (addr >> 16) & 0xFF);
  spi_xfer(SPI_BUS_FLASH, (addr >> 8) & 0xFF);
  spi_xfer(SPI_BUS_FLASH, addr & 0xFF);

//  spi_xfer(SPI_BUS_FLASH, 0x00); // Dummy byte


  for(u32 i=0; i < len; i++)
    buff[i] = spi_xfer(SPI_BUS_FLASH, 0x00);

  spi_slave_deselect();
}
Exemplo n.º 20
0
int main(void)
{
	struct spi_config config = { 0 };
	struct device *spi_mst_0 = device_get_binding("SPI_0");
	uint8_t manufacturer, device_id;
	int err;

	printk("SPI Example application\n");

	if (!spi_mst_0)
		return -EIO;

	config.config = SPI_MODE_CPOL | SPI_MODE_CPHA | SPI_WORD(8);
	config.max_sys_freq = 256;

	err = spi_configure(spi_mst_0, &config);
	if (err) {
		printk("Could not configure SPI device\n");
		return -EIO;
	}

	err = spi_slave_select(spi_mst_0, 1);
	if (err) {
		printk("Could not select SPI slave\n");
		return -EIO;
	}

	err = w25q80bl_read_id(spi_mst_0, &manufacturer, &device_id);
	if (err) {
		printk("Could not get Manufacturer and Device ID from SPI Flash\n");
		return -EIO;
	}

	printk("SPI Flash Manufacturer %x Device Id %x\n", manufacturer,
	       device_id);

	return 0;
}
Exemplo n.º 21
0
static int bmi160_transceive(struct device *dev, uint8_t *tx_buf,
			     uint8_t tx_buf_len, uint8_t *rx_buf,
			     uint8_t rx_buf_len)
{
	struct bmi160_device_config *dev_cfg = dev->config->config_info;
	struct bmi160_device_data *bmi160 = dev->driver_data;
	struct spi_config spi_cfg;

	spi_cfg.config = SPI_WORD(8);
	spi_cfg.max_sys_freq = dev_cfg->spi_freq;

	if (spi_configure(bmi160->spi, &spi_cfg) < 0) {
		SYS_LOG_DBG("Cannot configure SPI bus.");
		return -EIO;
	}

	if (spi_slave_select(bmi160->spi, dev_cfg->spi_slave) < 0) {
		SYS_LOG_DBG("Cannot select slave.");
		return -EIO;
	}

	return spi_transceive(bmi160->spi, tx_buf, tx_buf_len,
			      rx_buf, rx_buf_len);
}
Exemplo n.º 22
0
void m25_write_disable(void)
{
  spi_slave_select(SPI_SLAVE_FLASH);
  spi_xfer(SPI_BUS_FLASH, M25_WRDI);
  spi_slave_deselect();
}