static uint16_t SpiBcAccess(uint8_t addr, uint8_t rw, uint16_t data)
{
  uint16_t tmp;

  /* Enable CS */
  GPIO_PinOutClear(BSP_PORT_SPI_CS, BSP_PIN_SPI_CS);

  /* Write SPI address MSB */
  USART_Tx(BSP_SPI_USART_USED, (addr & 0x3) | rw << 3);
  /* Just ignore data read back */
  USART_Rx(BSP_SPI_USART_USED);

  /* Write SPI address  LSB */
  USART_Tx(BSP_SPI_USART_USED, data & 0xFF);

  tmp = (uint16_t) USART_Rx(BSP_SPI_USART_USED);

  /* SPI data MSB */
  USART_Tx(BSP_SPI_USART_USED, data >> 8);
  tmp |= (uint16_t) USART_Rx(BSP_SPI_USART_USED) << 8;

  /* Disable CS */
  GPIO_PinOutSet(BSP_PORT_SPI_CS, BSP_PIN_SPI_CS);

  return tmp;
}
/*
 *  Access multiple registers
 */
uint8_t CC1101_Radio::multi_register_access( uint8_t address, uint8_t access_mode, uint8_t* data, uint8_t length )
{
	uint8_t reg;
	uint8_t status;
	uint8_t count;

	GPIO_PinOutClear( _CC1101_SPI_CS_PIN );
	USART_Tx( _CC1101_USART, address | access_mode );
	status = USART_Rx( _CC1101_USART );

	for ( count = 0; count < length; count++ )
	{
		if ( ( access_mode == CC1101_READ_SINGLE ) || ( access_mode == CC1101_READ_BURST ) )
		{
			USART_Tx( _CC1101_USART, CC1101_SNOP );
			reg = USART_Rx( _CC1101_USART );
			data[count] = ( uint8_t )reg;
		}
		else
		{
			USART_Tx( _CC1101_USART, data[count] );
			status = USART_Rx( _CC1101_USART );
		}
	}

	GPIO_PinOutSet( _CC1101_SPI_CS_PIN );

	return status;
}
void NRF_ReceivePayload(uint8_t cmd, uint8_t bytes, uint8_t *buf)
{
  NRF_CSN_lo;
  NRF_USART->CMD = USART_CMD_CLEARRX;
  USART_Tx(NRF_USART, cmd);
  USART_Rx(NRF_USART);
  for (int i = 0; i < bytes; i++) {
	  USART_Tx(NRF_USART, 0xFF);
    buf[i] = USART_Rx(NRF_USART);
  }
  //while(!(NRF_USART->STATUS & USART_STATUS_TXC)) ;
  NRF_CSN_hi;
}
/*
 *  SPI register access
 */
uint8_t CC1101_Radio::register_access_SPI( uint8_t address, uint8_t access_mode, uint8_t data )
{
	uint8_t reg = 0;

	GPIO_PinOutClear( _CC1101_SPI_CS_PIN );
	USART_Tx( _CC1101_USART, address | access_mode ); // write the address byte
	USART_Rx( _CC1101_USART );                      // read reply
	USART_Tx( _CC1101_USART, data );                // write the data byte(s)
	reg = USART_Rx( _CC1101_USART );                // read and save the reply
	GPIO_PinOutSet( _CC1101_SPI_CS_PIN );

	return reg;
}
uint8_t NRF_ReadByte(uint8_t cmd)
{
  volatile uint8_t blah;
  NRF_CSN_lo;
  while((NRF_USART->STATUS & USART_STATUS_RXDATAV)) {
    blah = NRF_USART->RXDATA;
  }
  while(!(NRF_USART->STATUS & USART_STATUS_TXBL));
  NRF_USART->TXDATA = cmd;
  while(!(NRF_USART->STATUS & USART_STATUS_TXC));
  USART_Rx(NRF_USART);
  NRF_USART->TXDATA = 0x00;
  while (!(NRF_USART->STATUS & USART_STATUS_TXC)) ;
  NRF_CSN_hi;
  return USART_Rx(NRF_USART);
}
void NRF_SendCommand(uint8_t cmd, uint8_t data)
{
  NRF_CSN_lo;
  while(!(NRF_USART->STATUS & USART_STATUS_TXBL));
  NRF_USART->TXDATA = cmd;
  while(!(NRF_USART->STATUS & USART_STATUS_TXC));
  USART_Rx(NRF_USART);
  NRF_USART->TXDATA = data;
  while (!(NRF_USART->STATUS & USART_STATUS_TXC)) ;
  NRF_CSN_hi;
}
/*
 *  Send a strobe command
 */
uint8_t CC1101_Radio::strobe( uint8_t l_strobe )
{
	uint8_t reg = 0;

	GPIO_PinOutClear( _CC1101_SPI_CS_PIN );
	USART_Tx( _CC1101_USART, l_strobe );    // Write strobe command
	reg = USART_Rx( _CC1101_USART );        // Read reply
	GPIO_PinOutSet( _CC1101_SPI_CS_PIN );

	return reg;
}
Exemple #8
0
static int uart_gecko_poll_in(struct device *dev, unsigned char *c)
{
	const struct uart_gecko_config *config = dev->config->config_info;
	u32_t flags = USART_StatusGet(config->base);

	if (flags & USART_STATUS_RXDATAV) {
		*c = USART_Rx(config->base);
		return 0;
	}

	return -1;
}
/**************************************************************************//**
 * @brief SPI_TFT_Write Write registers/data to SSD2119 controller
 * @param reg
 *      Register to write to
 * @param data
 *      16-bit data to write into register
 * @note
 *      It's not possible to read back register value through SSD2119 SPI
 *      interface, so no SPI_TFT_ReadRegister function is implemented
 *****************************************************************************/
void SPI_TFT_WriteRegister(uint8_t reg, uint16_t data)
{
  /* Enable chip select */
  GPIO_PinOutClear(gpioPortD, 3);

  /* Select register first */
  USART1->CTRL = USART1->CTRL & ~USART_CTRL_BIT8DV;

  USART_Tx(USART1, reg & 0xFF);
  USART_Rx(USART1);

  /* Write data */
  USART1->CTRL = USART1->CTRL | USART_CTRL_BIT8DV;
  USART_Tx(USART1, (data & 0xff00) >> 8);
  USART_Rx(USART1);
  USART_Tx(USART1, (data & 0x00ff));
  USART_Rx(USART1);

  /* Clear chip select */
  GPIO_PinOutSet(gpioPortD, 3);
}
Exemple #10
0
void UART_1_RX_ISR(void)
{
    /* Check for RX data valid interrupt */
    if(UART_1_DEV->STATUS & UART_STATUS_RXDATAV) {
        /* Copy data into RX Buffer */
        uint8_t rxData = USART_Rx(UART_1_DEV);
        irq_read(UART_1, rxData);
    }
    if(sched_context_switch_request) {
        thread_yield();
    }
}
uint8_t NRF_Status(void)
{
  volatile uint8_t blah;
  NRF_CSN_lo;
  while((NRF_USART->STATUS & USART_STATUS_RXDATAV)) {
    blah = NRF_USART->RXDATA;
  }
  while(!(NRF_USART->STATUS & USART_STATUS_TXBL));
  NRF_USART->TXDATA = 0xFF;
  while (!(NRF_USART->STATUS & USART_STATUS_TXC)) ;
  NRF_CSN_hi;
  return USART_Rx(NRF_USART);
}
Exemple #12
0
uint8_t rcvr_spi(void)
{
  int i;
  //while (!(USART1->STATUS & USART_STATUS_TXBL)) ;
  //USART1->CMD = USART_CMD_CLEARRX | USART_CMD_CLEARTX;
  USART0->CTRL &= ~_USART_CTRL_TXBIL_MASK;
  USART0->CTRL |= USART_CTRL_TXBIL_HALFFULL;
  for (i = 0; i < 8; i++) {
    while(!(USART0->STATUS & USART_STATUS_TXBL)) ;
  	USART0->TXDATA = 0x07;
  }
  while (!(USART0->STATUS & USART_STATUS_TXC)) ;
  return USART_Rx(USART0);
}
Exemple #13
0
/**************************************************************************//**
 * @brief UART/LEUART IRQ Handler
 *****************************************************************************/
void UART1_RX_IRQHandler(void)
{
  if (UART1->STATUS & USART_STATUS_RXDATAV)
  {
    /* Store Data */
    rxBuffer[rxWriteIndex] = USART_Rx(UART1);
    rxWriteIndex++;
    rxCount++;
    if (rxWriteIndex == RXBUFSIZE)
    {
      rxWriteIndex = 0;
    }
    /* Check for overflow - flush buffer */
    if (rxCount > RXBUFSIZE)
    {
      rxWriteIndex = 0;
      rxCount      = 0;
      rxReadIndex  = 0;
    }
  }
}
Exemple #14
0
//USART2_TX_IRQHandler
void USART2_RX_IRQHandler(void)
{
  unsigned char c;

  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  if(USART2->STATUS & USART_STATUS_RXDATAV)
  {
    c = USART_Rx(USART2);
    if(usart2_input_handler != NULL) usart2_input_handler(c);
  }
  /*
  else
  {
      PRINTF("ERROR: control reg = 0x%lX", (SI32_USART_0->CONTROL.U32 & 0x7));
      // Disable all errors
      SI32_USART_0->CONTROL_CLR = 0x07;
  }
*/
  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Exemple #15
0
/**************************************************************************//**
 * @brief USART1 RX IRQ Handler
 *
 * Set up the interrupt prior to use
 *
 * Note that this function handles overflows in a very simple way.
 *
 *****************************************************************************/
void USART1_RX_IRQHandler(void)
{
  /* Check for RX data valid interrupt */
  if (uart->STATUS & USART_STATUS_RXDATAV)
  {
    /* Copy data into RX Buffer */
    uint8_t rxData = USART_Rx(uart);
    rxBuf.data[rxBuf.wrI] = rxData;
    rxBuf.wrI             = (rxBuf.wrI + 1) % BUFFERSIZE;
    rxBuf.pendingBytes++;

    /* Flag Rx overflow */
    if (rxBuf.pendingBytes > BUFFERSIZE)
    {
      rxBuf.overflow = true;
    }

    /* Clear RXDATAV interrupt */
    USART_IntClear(USART1, USART_IF_RXDATAV);
  }
}
Exemple #16
0
/**
 * Writes a byte to the ENC28J60 through SPI.
 * The chip must be selected prior to this write.
 * @param data the 8-bit data byte to write.
 */
void enc28j60_spi_write(uint8_t data)
{
  USART_Tx(USART0, data);
  USART_Rx(USART0);
}
Exemple #17
0
/**
 * Explicitly read a byte from the ENC28J60 by first sending the dummy byte
 * 0x00.
 * The chip must be selected prior to this write.
 * @return the data read.
 */
uint8_t enc28j60_spi_read(void)
{
  USART_Tx(USART0, 0);
  return USART_Rx(USART0);
}