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

esp32 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 SPITransaction;
	memset(&SPITransaction, 0, sizeof(spi_transaction_t));
	SPITransaction.length = 10 * 8;
	SPITransaction.tx_buffer = sendbuf;
	SPITransaction.rx_buffer = recvbuf;
	esp_err_t ret = spi_device_transmit(dev._SPIHandle, &SPITransaction);
	assert(ret == ESP_OK);
	if (_DEBUG_)
		ESP_LOGI(TAG, "W25Q64_readStatusReg2=%x %x %x", recvbuf[0], recvbuf[1], recvbuf[2]);
	vTaskDelay(pdMS_TO_TICKS(5));
	//	vTaskDelay(100);
	vSetSSN(1);
	vTaskDelay(pdMS_TO_TICKS(10));
	vSetSSN(0);
	vTaskDelay(pdMS_TO_TICKS(100));

	uint8_t cmd2[1] = {0x00};
	char sendbuf2[1];
	char recvbuf2[1];
	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);
   */

	spi_transaction_t recv2;
	memset(&recv2, 0, sizeof(recv2));
	recv2.length = 1 * 8;
	recv2.rxlength = 1 * 8;
 	recv2.rx_buffer = recvbuf2;
    
	ret = spi_device_polling_transmit(dev._SPIHandle, &recv2);
    memcpy(recvbuf2,recv2.rx_buffer,1);
	assert(ret == ESP_OK);
	if (_DEBUG_)
		ESP_LOGI(TAG, "W25Q64_readStatusReg2=%x", recvbuf2[0]);

  

标签:10,buffer,esp32,0x00,SPITransaction2,spi,流程,recv2
来源: https://www.cnblogs.com/hshy/p/16660247.html