Hi,
I am using STM32F103 Blue Pill Board connected a AS5600 magnetic encoder over PB11 SDA and PB10 SCL I2C lines.
The code upload to the STM32 Blue Pill over ST-LINK V2:
#include "Arduino.h"
#include <SoftwareSerial.h>
#include "AS5600.h"
#include "Wire.h"
TwoWire Wire2(PB11, PB10);
AS5600 as5600(&Wire2); // use default Wire
SoftwareSerial ser(PA3, PA2);
#define Serial ser
void setup()
{
Serial.begin(57600);
Serial.println(__FILE__);
Serial.print("AS5600_LIB_VERSION: ");
Serial.println(AS5600_LIB_VERSION);
as5600.begin(PB12); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
int b = as5600.isConnected();
Serial.print("Connect: ");
Serial.println(b);
//pinMode(PC13, OUTPUT);
}
void loop()
{
// Serial.print(millis());
// Serial.print("\t");
Serial.println(as5600.readAngle());
digitalWrite(LED_BUILTIN, LOW);
//Serial.print("\t");
//Serial.println(as5600.rawAngle());
// Serial.println(as5600.rawAngle() * AS5600_RAW_TO_DEGREES);
delay(2000);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
}
ESP32 to read the encoder data over serial:
#include "Arduino.h"
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial2.begin(57600);
}
void loop() {
//-------------------------------Check Serial Port---------------------------------------
while (Serial2.available()){
delay(1);
if(Serial2.available()>0){
char c = Serial2.read();
Serial.print(c);
}
}
}
When the reset button on STM32 Blue Pill is pressed:
␀␀␀␀␀␀���;␀␀␀␀␀␀␂␀␀␀␀␀␀␀␀␀␀␀␀src\main.cpp
AS5600_LIB_VERSION: 0.4.0
Connect: 1
0
and it stucks.
STM32 Blue Pill .ini file:
(I have used upload_flags = -c set CPUTAPID 0x2ba01477
due to the fake chip id)
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:blackpill_f103c8]
platform = ststm32
board = blackpill_f103c8
framework = arduino
upload_flags = -c set CPUTAPID 0x2ba01477
lib_deps =
robtillaart/AS5600@^0.4.0
Wire
khoih-prog/STM32_PWM@^1.0.1
monitor_speed = 9600
I want code to loop. What can be the problem?