whatsup
I am back.
The stupidest person in the world.
Anyway,,
Recently, I have been working on code that lets the Blackpill board communicate with other sensors, for example, the MPU6050.
with Interfaces; use Interfaces;
with A0B.Types.SVD; use A0B.Types.SVD;
with A0B.STM32F401.SVD.RCC; use A0B.STM32F401.SVD.RCC;
with A0B.STM32F401.SVD.GPIO; use A0B.STM32F401.SVD.GPIO;
with A0B.STM32F401.SVD.I2C; use A0B.STM32F401.SVD.I2C;
procedure my_blackpill_project is
Dummy_Bool : Boolean;
Dummy_UInt : A0B.Types.SVD.UInt32;
Result : A0B.Types.SVD.Byte;
procedure initialize is
begin
Dummy_Bool := False;
Dummy_UInt := 0;
RCC_Periph.AHB1ENR.GPIOBEN := True;
Dummy_Bool := RCC_Periph.AHB1ENR.GPIOBEN;
RCC_Periph.APB1ENR.I2C1EN := True;
Dummy_Bool := RCC_Periph.APB1ENR.I2C1EN;
GPIOB_Periph.MODER.Arr(6) := 2#10#;
GPIOB_Periph.MODER.Arr(7) := 2#10#;
GPIOB_Periph.OTYPER.OT.Arr(6) := True;
GPIOB_Periph.OTYPER.OT.Arr(7) := True;
GPIOB_Periph.PUPDR.Arr(6) := 2#01#;
GPIOB_Periph.PUPDR.Arr(7) := 2#01#;
GPIOB_Periph.AFRL.Arr(6) := 2#0100#; -- AF4 (I2C1_SCL)
GPIOB_Periph.AFRL.Arr(7) := 2#0100#;
I2C1_Periph.CR1.PE := False;
I2C1_Periph.CR2.FREQ := 42; -- APB1 clock frequency in MHz
I2C1_Periph.CCR.CCR := 210; -- 100 kHz I2C clock
I2C1_Periph.TRISE.TRISE := 43; -- Maximum rise time for 100 kHz
I2C1_Periph.CR1.PE := True;
I2C1_Periph.CR1.ACK := True;
end initialize;
function I2C1_Read_Reg(Dev_Addr : A0B.Types.SVD.UInt7; Reg_Addr : A0B.Types.SVD.Byte) return A0B.Types.SVD.Byte is
Dummy_SR2 : SR2_Register;
begin
--wait until bus free
while I2C1_Periph.SR2.BUSY loop
null;
end loop;
--write phase
I2C1_Periph.CR1.START := True;
while not I2C1_Periph.SR1.SB loop
null;
end loop;
I2C1_Periph.DR.DR := A0B.Types.SVD.UInt8(Integer(Dev_Addr) * 2); -- Write mode
while not I2C1_Periph.SR1.ADDR loop
null;
end loop;
Dummy_SR2 := I2C1_Periph.SR2; -- Clear ADDR flag
while not I2C1_Periph.SR1.TxE loop
null;
end loop;
I2C1_Periph.DR.DR := Reg_Addr;
while not I2C1_Periph.SR1.TxE loop
null;
end loop;
while not I2C1_Periph.SR1.BTF loop
null;
end loop;
-- read phase
I2C1_Periph.CR1.START := True; -- repeated start
while not I2C1_Periph.SR1.SB loop
null;
end loop;
I2C1_Periph.DR.DR := A0B.Types.SVD.UInt8(Integer(Dev_Addr) * 2 + 1); -- Read mode
while not I2C1_Periph.SR1.ADDR loop
null;
end loop;
Dummy_SR2 := I2C1_Periph.SR2; -- Clear ADDR flag
I2C1_Periph.CR1.ACK := False; -- NACK after next byte
I2C1_Periph.CR1.STOP := True; -- preparation for stop
while not I2C1_Periph.SR1.RxNE loop
null;
end loop;
return I2C1_Periph.DR.DR;
end I2C1_Read_Reg;
begin
RCC_Periph.AHB1ENR.GPIOCEN := True;
Dummy_Bool := RCC_Periph.AHB1ENR.GPIOCEN;
initialize;
GPIOC_Periph.MODER.Arr(13) := 2#01#; -- PC13 as output
Result := I2C1_Read_Reg(16#68#, 16#75#); -- Read WHO_AM_I register of MPU6050
--null; -- Use Result in a way that prevents optimization out
--loop
--if Result = 16#68# or Result = 16#98# then
GPIOC_Periph.ODR.ODR.Arr(13) := False; -- Set PC13 high
--else
--GPIOC_Periph.ODR.ODR.Arr(13) := True; -- Set PC13 low
--end if;
--end loop;
--end;
end my_blackpill_project;
This is my code that checks the WHO_AM_I register of MPU6050.
But I had trouble because it did not work; the LED was not blinking.
However, I had no way to debug it. I cannot check the value of the "result" variable, nor can I check which line my board is processing.
Thus, I decided to build a debugging environment.
So I installed OpenOCD and Cortex-Debug extension.
They enabled me to look inside my board.
Yeah Good.
But I did not figured out why my board did not blink.
Also, the result variable valued 152, which is 16#98#, originally it should be 16#68#. Also, it did not blink although debugers yellow arrow points "GPIOC_Periph.ODR.ODR.Arr(13) := False; -- Set PC13 high"
Hmm..
anyway,
how it does not works?
Someone figured out the possible problem, let me know it.
pls... I begyou
Top comments (0)