1599 views|1 replies

205

Posts

0

Resources
The OP
 

[RVB2601 creative application development] SVM40 UART communication implementation [Copy link]

 

The CDK platform of RVB2601 provides some development demo projects. Some of the projects corresponding to the serial port are only projects for serial port printing. Considering that we do not want to occupy the serial port for printing, we refer to the implementation method of netizen sipower and follow the APIhttps://yoc.docs.t-head.cn/yocbook/Chapter3-AliOS/HAL%E7%A1%AC%E4%BB%B6%E6%8A%BD%E8%B1%A1%E5%B1%82%E6%8E%A5%E5%8F%A3/UART.html?spm=a2cl5.25411629.0.0.3078180fy1MGca

To use UART1, the hardware connection is as follows:

The transplantation of the serial port function is relatively simple, but please note that under ch2601_evb\src\board.c, call csi_pin_set_mux to configure the serial port pins

Then svm40 accesses the temperature, humidity and organic matter concentration information in the sensor through commands. It should be noted that the SVM40_Start_measurement command must be used once before get_signals or get_raw_signals.

The sensor data read back cannot be used directly, but must be converted as shown in the following figure:

The code is implemented as follows:

void read_svm40(uint16_t *pvoc,uint16_t *phumi,uint16_t *phumi1,uint16_t *ptemp,uint16_t *ptemp1,uint8_t *data_buf)

{

// data_buf[5] data_buf[6] int16 provides the VOC Index (no unit) with a scaling factor of 10, e.g., an output of +250 corresponds to a VOC Index of +25.0.

*pvoc = data_buf[5];

*pvoc <<=8;

*pvoc += data_buf[6];

*pvoc =*pvoc / 10;

//data_buf[7] data_buf[8] int16 provides the relative humidity (in % RH) compensated for the temperature offset with a scaling factor of 100, e.g., an output of +2500 corresponds to +25.00 % RH.

*out = data_buf[7];

*phumi <<=8;

*out += data_buf[8];

*out1 = *out%100;

*out = *out/100;

//data_buf[9] data_buf[10] int16 provides the temperature (in °C) with a scaling factor of 200, e.g., an output of +5’000 corresponds to +25.00 C.

*ptemp = data_buf[9];

*ptemp <<=8;

*ptemp += data_buf[10];

*ptemp1 = *ptemp%200;

*ptemp = *ptemp/200;

}

int application_start(void)

{

int ret = -1;

uint32_t rx_size = 0;

char *pEnd;

float ret1,ret2;

csi_pin_set_mux(TEST_PIN_USART_TX, TEST_PIN_USART_TX_FUNC);

csi_pin_set_mux(TEST_PIN_USART_RX, TEST_PIN_USART_RX_FUNC);

/* uart port set */

uart1.port = TEST_USART_IDX;

/* uart attr config */

uart1.config.baud_rate = 115200;

uart1.config.data_width = DATA_WIDTH_8BIT;

uart1.config.parity = NO_PARITY;

uart1.config.stop_bits = STOP_BITS_1;

uart1.config.flow_control = FLOW_CONTROL_DISABLED;

uart1.config.mode = MODE_TX_RX;

/* init uart1 with the given settings */

ret = hal_uart_init(&uart1);

if (ret != 0) {

printf("uart1 init error !\n");

}

printf("uart1 init omplete !\n");

/* init the tx buffer */

memset(uart_data_buf,0,UART_BUF_SIZE);

hal_uart_send(&uart1, uart_tx_start, 7, UART_TX_TIMEOUT);

aos_msleep(50);

printf("start omplete !\n");

/* scan uart1 every 2000ms, if data received send it back */

while(1)

{

hal_uart_send(&uart1, uart_tx_get_signals, 7, UART_TX_TIMEOUT);

ret = hal_uart_recv_II(&uart1, uart_data_buf, UART_BUF_SIZE,&rx_size, UART_RX_TIMEOUT);

if(rx_size != 0)

{

read_svm40(&voc,&humi,&humi1,&temp,&temp1,&uart_data_buf);

}

memset(uart_data_buf,0,UART_BUF_SIZE);

/* sleep 2000ms */

aos_msleep(200);

};

After the transplantation is successful, the information obtained by the sensor is successfully displayed as shown below:

Latest reply

I am also a little brother who is troubled by serial port resources. Congratulations on achieving the goal!  Details Published on 2022-6-7 15:36
 
 

6841

Posts

11

Resources
2
 
I am also a little brother who is troubled by serial port resources. Congratulations on achieving the goal!
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list