2019-06-05 12:37 PM
The HX711 requires the MCU to send an exact number of clock pulses to capture a 24 bit value, then the clock signal must remain low until the HX711 indicates its ready to transmit again, using the data line. I tried to use a GPIO pin to generate the clock signal manually with pin_set and pin_reset calls, which works in that it creates a clock signal at the frequency of the APB, but the amplitude is only 100 mv. When I plug the clock signal into the HX711 the signal becomes low level noise. Here is the pin config:
/*Configure GPIO pin : SCLK_Pin */
GPIO_InitStruct.Pin = SCLK_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(SCLK_GPIO_Port, &GPIO_InitStruct);
and here is the clock gen code:
// read 24 data bits
for (i = 0; i < 24; i++) {
HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_SET);
buffer <<= 1;
HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_RESET);
buffer += HAL_GPIO_ReadPin (SDATA_GPIO_Port, SDATA_Pin);
}
I should be getting a 3.3V clock signal. Any suggestions?
2019-12-03 07:14 AM
It may be working. The clock signals are generated in HX711_Value() by toggling the clock pin. Its a peculiar protocol. The rate is limited by the speed of the clock controlling that pin (APB1 or APB2). This must be less than 5 MHz for the load cell to keep up. Did you try pressing on the load cell to see it the number changes?
2019-12-03 07:28 AM
I just re-read your question and saw that the amplitude is too low. Try using another pin (I had the same problem). On an stmf413 pins PA5, PA6 or PA7 work well.
2019-12-03 07:32 AM
ok, got a bit confused there. I was reading MY original question. Ha!
2019-12-03 07:36 AM
Hi again!
I added some function to my code so now I am getting the clock signal:
void power_down() {
HAL_GPIO_WritePin(HS711SCK_GPIO_Port, HS711SCK_Pin, 0);
HAL_GPIO_WritePin(HS711SCK_GPIO_Port, HS711SCK_Pin, 1);
}
void power_up() {
HAL_GPIO_WritePin(HS711SCK_GPIO_Port, HS711SCK_Pin, 0);
}
I use it like that:
while (1)
{
power_up();
meres =HX711_Average_Value(hx11, 1);
//HX711_Value(hx11);
meres = meres-offs;
HAL_Delay(100);
power_down();
//meres = HX711_AverageValue(hx11, times);
HAL_Delay(500);
HAL_UART_Transmit(&huart2, masage, sprintf(masage,"%d\n\r", meres),1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
So now I'am finally getting back something else than 8388608 but they are still random numbers for some reason.
Here is my setup:
2020-02-21 06:18 AM
Hİ Atilla_S, Did you solve the problem? "8388608" value is seen when I follow the same steps.
2020-02-21 06:41 AM
Hi same thing here, working on it :persevering_face:
2020-02-23 08:28 AM
The following code works. Make sure that the buffer (and returned value) are defined uint32_t. The line "buffer ^= 0x800000;" is essential to avoid the huge #'s starting with 8.
uint32_t CB_SPI_Receive (void) {
uint32_t buffer = 0U;
int i, j, k = 1;
// wait for SDATA to go lo
while (HAL_GPIO_ReadPin (SDATA_GPIO_Port, SDATA_Pin)) ;
// wait 300 ns
for (j = 0; j < 5; j++) k += 19;
// read 24 data bits
for (i = 0; i < 24; i++) {
HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_SET);
buffer <<= 1;
HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_RESET);
buffer += HAL_GPIO_ReadPin (SDATA_GPIO_Port, SDATA_Pin);
}
// generate one or 3 more clock pulse to set gain for next sample and set bit 23 before returning
buffer ^= 0x800000;
// for (i = 0; i < 2; i++) {
HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_RESET);
// }
return buffer;
}
2020-02-23 08:29 AM
2020-02-23 08:30 AM
2020-02-23 08:44 AM
Gonna check it out for sure, cheers mate ☺�?