Netduino Plus 2 board + BME280

Post here first, or if you can't find a relevant section!
Post Reply
jarwil
Posts: 12
Joined: Wed Nov 23, 2022 2:06 pm

Netduino Plus 2 board + BME280

Post by jarwil »

Hi all.
Recently I successfully got ethernet running on a Netduino Plus 2.
Thread from: viewtopic.php?t=1771
Now I have a problem with libraries for temperature sensors. I am trying to read the temperature from DHT22 and BME280, unfortunately without success, none of the libraries work. Could it be a problem with configuring the clock settings?
I would like to add that I tested the libraries for the above-mentioned sensors on the STM32F4-Discovery board, Leonardo and also on BluePill. Everything works on these boards.

Can anyone verify that the settings I used are correct for Netduino Plus 2?

Code: Select all

extern "C" void SystemClock_Config(void)
{

	RCC_OscInitTypeDef RCC_OscInitStruct = {};
	RCC_ClkInitTypeDef RCC_ClkInitStruct = {};

	/**Configure the main internal regulator output voltage
	*/
	__HAL_RCC_PWR_CLK_ENABLE();

	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

	/**Initializes the CPU, AHB and APB busses clocks
	*/
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
	RCC_OscInitStruct.HSEState = RCC_HSE_ON;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
	RCC_OscInitStruct.PLL.PLLM = 25;
	RCC_OscInitStruct.PLL.PLLN = 336;
	RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
	RCC_OscInitStruct.PLL.PLLQ = 7;
	if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
		Error_Handler();
	}

	/**Initializes the CPU, AHB and APB busses clocks
	*/
	RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
		| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
	RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

	if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
		Error_Handler();
	}

	/* Ensure CCM RAM clock is enabled */
	__HAL_RCC_CCMDATARAMEN_CLK_ENABLE();

}

void setup()
{
	//clock setup
	//SystemClock_Config(); (extern)
	
	//PA8 as clock for enc28J60
	HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1);
	
	//PB4 as MISO
	SPI.setMISO(PB4);
	
	//PC8 as chip sellect
	Ethernet.init(PC8);
	
	//start ethernet
	Ethernet.begin(mac, Eth_ModuleIP);
}
Also I changed the definition of HSE_VALUE in file stm32f4xx_hal_conf_default.h to 25000000.
economicair
Posts: 1
Joined: Wed Jan 04, 2023 6:38 am

Re: Netduino Plus 2 board + BME280

Post by economicair »

jarwil wrote: Thu Dec 15, 2022 6:37 pm Hi all.
Recently I successfully got ethernet running on a Netduino Plus 2.
Thread from: viewtopic.php?t=1771phrazle
Now I have a problem with libraries for temperature sensors. I am trying to read the temperature from DHT22 and BME280, unfortunately without success, none of the libraries work. Could it be a problem with configuring the clock settings?
I would like to add that I tested the libraries for the above-mentioned sensors on the STM32F4-Discovery board, Leonardo and also on BluePill. Everything works on these boards.

Can anyone verify that the settings I used are correct for Netduino Plus 2?

Code: Select all

extern "C" void SystemClock_Config(void)
{

	RCC_OscInitTypeDef RCC_OscInitStruct = {};
	RCC_ClkInitTypeDef RCC_ClkInitStruct = {};

	/**Configure the main internal regulator output voltage
	*/
	__HAL_RCC_PWR_CLK_ENABLE();

	__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

	/**Initializes the CPU, AHB and APB busses clocks
	*/
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
	RCC_OscInitStruct.HSEState = RCC_HSE_ON;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
	RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
	RCC_OscInitStruct.PLL.PLLM = 25;
	RCC_OscInitStruct.PLL.PLLN = 336;
	RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
	RCC_OscInitStruct.PLL.PLLQ = 7;
	if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
		Error_Handler();
	}

	/**Initializes the CPU, AHB and APB busses clocks
	*/
	RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
		| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
	RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
	RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
	RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
	RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

	if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
		Error_Handler();
	}

	/* Ensure CCM RAM clock is enabled */
	__HAL_RCC_CCMDATARAMEN_CLK_ENABLE();

}

void setup()
{
	//clock setup
	//SystemClock_Config(); (extern)
	
	//PA8 as clock for enc28J60
	HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1);
	
	//PB4 as MISO
	SPI.setMISO(PB4);
	
	//PC8 as chip sellect
	Ethernet.init(PC8);
	
	//start ethernet
	Ethernet.begin(mac, Eth_ModuleIP);
}
Also I changed the definition of HSE_VALUE in file stm32f4xx_hal_conf_default.h to 25000000.
Okay, so now I'm having trouble with temperature sensor library issues. I've tried using several libraries to read the temperature from DHT22 and BME280, but to no avail. It can be time zone issues.
jarwil
Posts: 12
Joined: Wed Nov 23, 2022 2:06 pm

Re: Netduino Plus 2 board + BME280

Post by jarwil »

What do you mean the problem could be with the timezone? What can I do or check in this case?
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Netduino Plus 2 board + BME280

Post by ozcar »

jarwil wrote: Wed Jan 04, 2023 4:29 pm What do you mean the problem could be with the timezone? What can I do or check in this case?
I never tried to get a Netduino, or any custom board to work, and I can't say if what you tried is correct, but it is hard to see why a sensor library would stop working altogether because some time zone was incorrect.

Certainly such libraries could have trouble if basic time-related functions like delay(), millis() and micros() are not working correctly. Some libraries may also use the defined value for F_CPU to calculate something, but I'm not sure if anything at all could work correctly if that was wrong. In your other thread you mentioned trouble with millis() and micros(), but it is not clear to me if you still have that problem after you tried to change the HSE_VALUE.

If those time-related functions are working correctly, I think you would need to be a bit more specific about exactly what library you are trying to use, how the sensor is attached (particularly for something like BME280 where there is a choice), and in what way it does not work.
jarwil
Posts: 12
Joined: Wed Nov 23, 2022 2:06 pm

Re: Netduino Plus 2 board + BME280

Post by jarwil »

One of Murphy's laws says:
It works better if you plug it in.
What I wanted to do, I have already done on BluePill and a separate ENC28J60. The netduino board was already intended for the archive box.
Thanks to your answer, I gave Netduino another chance :)
This time I decided to check HW.
What was my surprise when I saw that where there should be 5V there was 0V. The sensors I tested had no power.
A quick glance at the diagram and everything became clear :)
HeadersPower.png
HeadersPower.png (20.58 KiB) Viewed 654 times
Now it work perfectly.
result.png
result.png (1.61 KiB) Viewed 654 times
Also the ethernet works well.
jsonResponse.png
jsonResponse.png (11.24 KiB) Viewed 654 times
Thank You!
Post Reply

Return to “General discussion”