//向SSD1306写入一个字节。
//dat:要写入的数据/命令
//cmd:数据/命令标志 0,表示命令;1,表示数据;
void OLED_WR_Byte(uint8_t dat,uint8_t cmd)
{	
	//uint8_t i;		
  
 spi0_tx_data[0]=dat;	
	if(cmd)
	  OLED_RS_Set();
	else 
	  OLED_RS_Clr();		  
#if 0
	OLED_CS_Clr();

	for(i=0;i<8;i++)
	{			  
		OLED_SCLK_Clr();
		if(dat&0x80)
		   OLED_SDIN_Set();
		else 
		   OLED_SDIN_Clr();
		OLED_SCLK_Set();
		dat<<=1;   
	}		
	OLED_CS_Set();
#endif	
	//NRF_SPI0
    if(!spi_master_tx_rx(spi_base_address, 1, (const uint8_t *)spi0_tx_data, (uint8_t*) spi0_rx_data))
//	if(!spi_master_tx_rx(NRF_SPI0, 1, (const uint8_t *)spi0_tx_data, (uint8_t*) spi0_rx_data))
    {
        return ;
    }

	OLED_RS_Set();   	  
} 
Exemplo n.º 2
0
/**@brief Receive bytes from the card
 *
 * @param[in]   data   Pointer to where to save the data received.
 * @param[in]   bytes  Number of bytes to receive.
 */
void receive_mmc(uint8_t *data, uint32_t bytes){
	uint8_t tx[bytes];

	for(uint32_t i = 0; i < bytes; i++)
		tx[i] = 0xFF;

	spi_master_tx_rx(sdcard_spi_addr, bytes, tx, data);
}
Exemplo n.º 3
0
/**@brief Function for executing a single SPI transaction.
 *
 * @retval true  Operation success.
 * @retval false Operation failure. 
 */
static bool test_spi_tx_rx(void)
{    
    uint8_t tx_data[TX_RX_BUF_LENGTH] = {0}; 
    uint8_t rx_data[TX_RX_BUF_LENGTH] = {0};  

    uint32_t * p_spi_base_address = spi_master_init(SPI0, SPI_MODE0, true);
    if (p_spi_base_address == NULL)
    {
        return false;
    }
      
    return spi_master_tx_rx(p_spi_base_address, TX_RX_BUF_LENGTH, tx_data, rx_data);    
}
Exemplo n.º 4
0
int read_register(uint8_t register_address, int num_bytes, uint8_t* values) 
{
    if(num_bytes > 1)   //  (uint8_t*)values
        tx_data[0] = 0xC0 | register_address;
    else
        tx_data[0] = 0x80 | register_address;

    if(!spi_master_tx_rx(spi_ba, num_bytes, tx_data, values)) 
    {
      return -1;
    }

    return 0;
}
Exemplo n.º 5
0
int write_register(uint8_t register_address, uint8_t value) 
{
    uint8_t tx[2];
    tx[0] = register_address;
    tx[1] = value;
    uint8_t rx[2];
    
    if(!spi_master_tx_rx( spi_ba, 2, tx, rx)) 
    {
        return -1;
    }
    
    return 0;
}
Exemplo n.º 6
0
/**@brief Send bytes to the card
 *
 * @param[in]   data   Pointer to the data to be sent.
 * @param[in]   bytes  Number of bytes to be sent.
 */
void send_mmc(const uint8_t *data, uint32_t bytes){
	uint8_t rx[bytes];

	spi_master_tx_rx(sdcard_spi_addr, bytes, data, rx);
}