示例#1
0
/*
 * 函数:user_spi_write_byte
 * 说明:SPI写一个字节
 */
void ICACHE_FLASH_ATTR
user_spi_write_byte(u8 data)
{
#if defined(HARD_SPI)
	u32 send_data[1] = {data};
	SpiData spiData;
    spiData.cmd = MASTER_WRITE_DATA_TO_SLAVE_CMD;
    spiData.cmdLen = 0;
    spiData.addr = NULL;
    spiData.addrLen = 0;
    spiData.data = send_data;
    spiData.dataLen = 1;
    SPIMasterSendData(SpiNum_HSPI, &spiData);

#elif defined(SOFT_SPI)
    u8 i;
    CS_0();
	for(i = 0; i < 8; i++){
		if (data & 0x80){
			MOSI_1();
		}else{
			MOSI_0();
		}
		SCK_0();
		data <<= 1;
		//user_spi_delay_us(50);
		SCK_1();
	}
	CS_1();
#endif
}
示例#2
0
static void fn_send_byte(uint8 addr, uint8 out)
{
    SpiData spi_data;

    os_printf("\r\n =============   spi init master   ============= \r\n");

//  Test 8266 slave.Communication format: 1byte command + 1bytes address + x bytes Data.
    os_printf("\r\n Master send 1 bytes data to slave(sx1278)\r\n");

    spiData.cmd     = MASTER_WRITE_DATA_TO_SLAVE_CMD;
    spiData.cmdLen  = 1;
    spiData.addr    = &addr;
    spiData.addrLen = 1;
    spiData.data    = out;
    spiData.dataLen = 1;
    SPIMasterSendData(SpiNum_HSPI, &spiData);

    // spi_mast_byte_write(SPI, out);
}