2020-11-11 01:19 AM
i am trying to bit bang 14 bits grey code. my output is not steady
uint16_t readbits(uint16_t dataPin, uint16_t clockPin) {
uint16_t value =0;
for (int i = 0; i <14; ++i) {
value <<= 1;
HAL_GPIO_WritePin(GPIOC, clockPin, GPIO_PIN_RESET);
delay_us(20);
HAL_GPIO_WritePin(GPIOC, clockPin, GPIO_PIN_SET);
delay_us(20);
value |= HAL_GPIO_ReadPin(GPIOC, dataPin);
}
return value;
}
i think HAL_GPIO_ReadPin is not fast enough
in the while loop ()
DATA1 = readbits(DATA1_L_Pin, CLK_SSI_PORT_Pin);
how can change HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_2); for example to read register status?
2020-11-11 07:52 AM
with the line: GPIOC->BSRR = clockPin << 16; this is for specific GPIO_PIN_1 ?
2020-11-11 10:02 AM
2020-11-12 02:05 AM
it worked ! i missed one falling edge, because ssi word starts when de clock goes low and then up. Than i need the 14 bit data burst.
with your answer and Ozone i made the following function: it reads 4 pins at the same clock
void CLK_and_reading(uint16_t clockPin) {
DATA1 =0; DATA2 =0; DATA3 =0; DATA4 =0;
GPIOC->BSRR = clockPin << 16; delay_us(4);
GPIOC->BSRR = clockPin; delay_us(4);
for (int i = 0; i <14; ++i) {
DATA1 <<= 1; DATA2 <<= 1; DATA3 <<= 1; DATA4 <<= 1;
GPIOC->BSRR = clockPin << 16; delay_us(4);
GPIOC->BSRR = clockPin;
if (GPIOC->IDR & DATA1_L_Pin) { DATA1 |= 1; }
if (GPIOC->IDR & DATA2_L_Pin) { DATA2 |= 1; }
if (GPIOC->IDR & DATA3_L_Pin) { DATA3 |= 1; }
if (GPIOC->IDR & DATA4_L_Pin) { DATA4 |= 1; }
delay_us(1);
}
}