Added CO2 MODBUS readout
This commit is contained in:
		
							parent
							
								
									6830fabbd3
								
							
						
					
					
						commit
						8d2f2a6486
					
				| @ -50,6 +50,20 @@ const uint16_t tim21_prescaler = 60000-1; // 100Hz | |||||||
| //const uint16_t tim21_period = 12000-1; // 60s
 | //const uint16_t tim21_period = 12000-1; // 60s
 | ||||||
| const uint16_t tim21_period = 1200-1; // 6s
 | const uint16_t tim21_period = 1200-1; // 6s
 | ||||||
| //const uint16_t tim21_period = 200-1; // 1s
 | //const uint16_t tim21_period = 200-1; // 1s
 | ||||||
|  | /* Variables to store the measured data */ | ||||||
|  | int CO2, T_SCD4x, RH_SCD4x; | ||||||
|  | int T_SHT4x, RH_SHT4x; | ||||||
|  | uint16_t sps30_measured_data[10]; | ||||||
|  | /* TODO maybe use union for measured value?
 | ||||||
|  |  * this would make modbus register readout easier */ | ||||||
|  | union { | ||||||
|  | 	struct { | ||||||
|  | 		uint16_t CO2; | ||||||
|  | 		uint16_t T_SCD4x; | ||||||
|  | 		uint16_t RH_SCD4x; | ||||||
|  | 	}; | ||||||
|  | 	uint16_t array[3]; | ||||||
|  | } measured_values; | ||||||
| /* USER CODE END PV */ | /* USER CODE END PV */ | ||||||
| 
 | 
 | ||||||
| /* Private function prototypes -----------------------------------------------*/ | /* Private function prototypes -----------------------------------------------*/ | ||||||
| @ -66,6 +80,13 @@ static void MX_TIM21_Init(void); | |||||||
| /* USER CODE BEGIN 0 */ | /* USER CODE BEGIN 0 */ | ||||||
| int8_t modbus_slave_callback(modbus_transaction_t *transaction) | int8_t modbus_slave_callback(modbus_transaction_t *transaction) | ||||||
| { | { | ||||||
|  | 	if (transaction->function_code == MODBUS_READ_INPUT_REGISTERS) { | ||||||
|  | 		// TODO select reasonable register numbers and implement
 | ||||||
|  | 		// readout of all measured variables
 | ||||||
|  | 		if (transaction->register_number == 30010) { // register number 30010 (randomly selected)
 | ||||||
|  | 			transaction->input_registers[0] = CO2; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	return MODBUS_ERROR_FUNCTION_NOT_IMPLEMENTED; /* nothing implemented yet! TODO */ | 	return MODBUS_ERROR_FUNCTION_NOT_IMPLEMENTED; /* nothing implemented yet! TODO */ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -147,11 +168,6 @@ int main(void) | |||||||
| 	  sps30_is_connected = 1; | 	  sps30_is_connected = 1; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /* Variables to store the measured data */ |  | ||||||
|   int CO2, T_SCD4x, RH_SCD4x; |  | ||||||
|   int T_SHT4x, RH_SHT4x; |  | ||||||
|   uint16_t sps30_measured_data[10]; |  | ||||||
| 
 |  | ||||||
|   /* Wait 1000ms for sensors initialization */ |   /* Wait 1000ms for sensors initialization */ | ||||||
|   /* SHT4x Init Time: max 1 	ms 	(datasheet pg. 8) */ |   /* SHT4x Init Time: max 1 	ms 	(datasheet pg. 8) */ | ||||||
|   /* SCD4x Init Time: max 1000 	ms 	(datasheet pg. 6) */ |   /* SCD4x Init Time: max 1000 	ms 	(datasheet pg. 6) */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 dooku
						dooku