其他分享
首页 > 其他分享> > spi一个标准流程

spi一个标准流程

作者:互联网

uint8_t cmd[10] = {0x55, 0x00, 0xB0, 0x99, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00};
	cmd[9] = getLRCx(&cmd[1], 8);
	char sendbuf[10];
	char recvbuf[10];

	memcpy(sendbuf, cmd, 10);

	// vSetSSN(0);
//	 vSetMOSI(1);
//	  vSetMISO(1);
	//vSetSCK(1);

	vSetSSN(0);
	vTaskDelay(pdMS_TO_TICKS(100));
	spi_transaction_t recv;
	memset(&recv, 0, sizeof(recv));
	recv.length = 10 * 8;
	recv.rxlength = 10 * 8;
	recv.rx_buffer = recvbuf;
	esp_err_t ret = spi_device_polling_transmit(dev._SPIHandle, &recv);
    
	spi_transaction_t SPITransaction;
	memset(&SPITransaction, 0, sizeof(spi_transaction_t));
	SPITransaction.length = 10 * 8;
	SPITransaction.tx_buffer = sendbuf;
	SPITransaction.rx_buffer = recvbuf;
	ret = spi_device_transmit(dev._SPIHandle, &SPITransaction);
	assert(ret == ESP_OK);
	vTaskDelay(pdMS_TO_TICKS(5));
	//	vTaskDelay(100);
	vSetSSN(1);
	vTaskDelay(pdMS_TO_TICKS(10));
	vSetSSN(0);
	vTaskDelay(pdMS_TO_TICKS(100));
	if (_DEBUG_)
		ESP_LOGI(TAG, "W25Q64_readStatusReg2=%x %x %x", recvbuf[0], recvbuf[1], recvbuf[2]);

	uint8_t cmd2[1] = {};
	char sendbuf2[1];
	char recvbuf2[100];
	memcpy(sendbuf2, cmd2, 1);
 
	spi_transaction_t SPITransaction2;
	memset(&SPITransaction2, 0, sizeof(spi_transaction_t));
	SPITransaction2.length = 1 * 8;
	SPITransaction2.tx_buffer = sendbuf2;
	SPITransaction2.rx_buffer = recvbuf2;
	ret = spi_device_transmit(dev._SPIHandle, &SPITransaction2);
	assert(ret == ESP_OK);
	if (_DEBUG_)
		ESP_LOGI(TAG, "W25Q64_readStatusReg2=%x %x %x", recvbuf2[0], recvbuf2[1], recvbuf2[2]);

  

标签:recvbuf,10,标准,SPITransaction,流程,SPITransaction2,spi,recv
来源: https://www.cnblogs.com/hshy/p/16660218.html