trying to interface with an HX711 load cell amp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 7: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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 7: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 7:32 AM
ok, got a bit confused there. I was reading MY original question. Ha!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-03 7: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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-21 6:18 AM
HÄ° Atilla_S, Did you solve the problem? "8388608" value is seen when I follow the same steps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-21 6:41 AM
Hi same thing here, working on it :persevering_face:​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-23 8: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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-23 8:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-23 8:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-02-23 8:44 AM
Gonna check it out for sure, cheers mate ☺�?​
