Read by UART TX line

alex_vilella
Posts: 1
Joined: Thu Jul 25, 2019 6:32 am

Read by UART TX line

Postby alex_vilella » Thu Jul 25, 2019 7:02 am

Hello.
I am trying to implement an SDI-12 sensor by UART, but for that I have to read the sensor data by the TX line of the UART.
I can communicate with the sensor, but I can't pick up the answer.
Someone knows some solution in c. I use the esp-idf library.

I have tried changing the pins before reading with 'uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, TX_IO_NUM, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);''.
This doesn't work for me.
I've also tried uninstalling UART and configuring the pins, but neither.

This is a small example of my code:

Code: Select all

	
UART_Change_Parameter(uint32_t baudrate, uint32_t tx_pin_num, uint32_t rx_pin_num) {
	/* Remove UART driver */
	uart_driver_delete(UART_NUM_2);

	/* Configure the TX pin. */
	SmartSpot_Utils_UART_UART2Mux_Configure_Pins_SDI12();

	/* Initialize uart */
	uart_config_t uart2_config = {
	        .baud_rate = baudrate,
	        .data_bits = UART_DATA_7_BITS,
	        .parity    = UART_PARITY_EVEN,
	        .stop_bits = UART_STOP_BITS_1,
	        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
	        .rx_flow_ctrl_thresh = 122,
	 };

	 /*  Apply UART configuration on UART 2 */
	 uart_param_config(UART_NUM_2, &uart2_config);

	 /* Set PIN configuration on UART 2 */
	 uart_set_pin(SMARTSPOT_UTILS_UART_UART2_NUM, tx_pin_num, rx_pin_num, SMARTSPOT_UTILS_UART_UART2_RTS, 	SMARTSPOT_UTILS_UART_UART2_CTS);

	 /* Install driver for UART2 */
	uart_driver_install(UART_NUM_2, UART2_BUF_SIZE, UART2_BUF_SIZE, UART2_QUEUE_SIZE, &uart2_queue, 0);
}
[Codebox=c file=Untitled.c][/Codebox]
And this is the part of the communication with the sensor:

Code: Select all

bool Uart_Driver_Execute_Read_Sensor_Values(){

	UART_Change_Parameter(1200, UART2_TX, UART2_RX);

	wakeSensors();

	// Write
	char * command = "0I!\0";

	/* Write Command */
	ESP_LOGI(tagg, "Sending (%d): %s", strlen(command),(const char*)command);


	uart_write_bytes(UART_NUM_2, (const char*)command, strlen(command));

	uart_wait_tx_done(UAR_NUM_2, 500/portTICK_PERIOD_MS);

	//uart_set_pin(UART_NUM_2,
	//			UART_PIN_NO_CHANGE,	// Tx
	//			UART2_TX, 			//  Rx
	//			UART_PIN_NO_CHANGE,
	//			UART_PIN_NO_CHANGE);
	
	UART_Change_Parameter(1200, UART_PIN_NO_CHANGE, UART2_TX);
	
	int len = uart_read_bytes(UART_NUM_2, uart_rx_buffer, UART_BUFFER_SIZE, 250/portTICK_PERIOD_MS);
	ESP_LOGI(tagg, "Len: %d -> %s", len, uart_rx_buffer);

	return true;

}
[Codebox=c file=Untitled.c][/Codebox]
I've tried several options and none of them have worked.
Some idea
Thank you.

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: Read by UART TX line

Postby ESP_houwenxiang » Tue Jul 30, 2019 4:15 am

Hi, alex_vilella
How do you swap the TX_pin and RX_pin ? Which IO are used?
wookooho

Who is online

Users browsing this forum: Majestic-12 [Bot] and 136 guests