arduino shiftIn function to STM32CubeIDE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-30 7:36 AM
I made a test code in arduino to read SSI. How can I make the shiftin function work correctly in the stm32 controllers? . In the stm32cubeIDE I can't manage to make it work like in the arduino ide.
In the shiftin function the variables: data_pin, clock_pin and bit_count are in lower case. In the stm32cubeIDE I can't manage to link the outputs to this function:
arduino code:
const int CLOCK_PIN = 8;
const int DATA_PIN1 = 14;
const int DATA_PIN2 = 15;
const int DATA_PIN3 = 16;
const int DATA_PIN4 = 17;
const int BIT_COUNT = 14;
void setup() {
//setup our pins
pinMode(DATA_PIN1, INPUT);
pinMode(DATA_PIN2, INPUT);
pinMode(DATA_PIN3, INPUT);
pinMode(DATA_PIN4, INPUT);
pinMode(CLOCK_PIN, OUTPUT);
//give some default values
digitalWrite(CLOCK_PIN, HIGH); //klok hoog voor het verkrijgen van data
Serial.begin(115200);
}
void loop() {
int reading = readPosition();
}
float readPosition() {
unsigned long sample1 = shiftIn(DATA_PIN1, CLOCK_PIN, BIT_COUNT);
unsigned long sample2 = shiftIn(DATA_PIN2, CLOCK_PIN, BIT_COUNT);
unsigned long sample3 = shiftIn(DATA_PIN3, CLOCK_PIN, BIT_COUNT);
unsigned long sample4 = shiftIn(DATA_PIN4, CLOCK_PIN, BIT_COUNT);
//unsigned long sample2 = graytobin(sample1, BIT_COUNT);
delayMicroseconds(25); // time-out
return;
}
//read in a byte of data from the digital input
unsigned long shiftIn(const int data_pin, const int clock_pin, const int bit_count) {
unsigned long data = 0;
for (int i=0; i<BIT_COUNT; i++) {
data <<= 1;
digitalWrite(clock_pin,LOW);
delayMicroseconds(1);
digitalWrite(clock_pin,HIGH);
delayMicroseconds(1);
data |= digitalRead(data_pin);
}
return data;
}
in STMcubeIDE:
unsigned long shiftIn(const int data_l_pin, const int clk_ssi_port_pin, const int bit_count) {
unsigned long data = 0;
for (int i=0; i<BIT_COUNT; i++) {
data <<= 1;
HAL_GPIO_WritePin(clk_ssi_port_pin, GPIO_PIN_RESET);
HAL_Delay(1);
HAL_GPIO_WritePin(clk_ssi_port_pin, GPIO_PIN_SET);
HAL_Delay(1);
data |= HAL_GPIO_ReadPin(DATA1_L_Pin);
}
return data;
}
this wont work and cant find a better solution for this, do someone have any tips for create a better function or way to do this connection and read the data from the data pins. In arduino it looks that this function is used for al the data pins.
- Labels:
-
GPIO-EXTI
-
STM32CubeIDE
-
STM32duino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-30 11:13 AM
HAL_GPIO_WritePin takes 3 arguments, you're only feeding in two. Pins are specified by both a port and a pin number.
