Open mavishak opened 3 years ago
23.12.2020: We debugged usart_init() and write() it seems that they work as they are supposed to But we haven't managed to view the transmitted letter on the screen. Need to dig deeper - and solve the problem.
27.12.2020: When debugging write() USART2->DR and TXE flag in USART2->SR are not changing. This might be normal. There might be a problem with ST-LINK/v.2 Note: Changed to branch main_v.2 because of problems in the main branch
27.12.2020: We managed to connect TeraTerm and USART2 by enabling PA2. Problem: TeraTerm is not displaying character correctly.
(...a few hours later) 27.12.2020 TeraTerm still printing garbage. Got Interrupt Tx to work. TC interrupt should come next.
30.12.2020: _Good News: Got TeraTerm To work! Bad News: I have no idea why it's working... :/_ Basically, the problem is in the setting of the BAUD RATE. We need to get a better understanding of its calculation and of the clock tree.
How is it working: TeraTerm speed is set to 2400 and USART_BRR is set to 0xD05. (I don't know if it matters but - GPIOA is configured to a speed of 2 MHz.) Note: Interrupt is now disabled - Instructions from above.
I am adding 3 images displaying what worked: (click to make larger)
I didn't notice before but it seems that in the working version of USART, RCCAFIO is disabled (or is it really?)_.
The reason behind it is as we were debugging we noticed that the configuration of RCCAFIO does not affect the garbage displayed on the screen, so we commented it out (and forgot about it)._
So I guess another question would be: When does RCC_AFIO need to be enabled?
03.01.2021: _(hc-sr501pirsensor.c) USART2 is now configured to respond to the sensor interrupt. TBD: Implement triggering of USART with event_queue. Question: Should the handler init() the usart and then trigger write() or should UART be initialized in advance. My gut tells me that the handler should do both...
03.01.2021: (usart.c) A message is now sent to the screen rather than one letter. The problems listed above are still valid :/
HC-SR501 PIR Sensor (click to make larger)
The sensor is now connected to USART. The next step is to connect the STM32 and ESP8266 Wi-Fi module.
08.01.2021: SOLVED! :) USART IS NOW OFFICIALLY WORKING with a baud rate of 9600 bps. The USART2 clock is PCLK1 is by default only 8MHz NOT 36MHz. (see RM p.798 for BRR calculation and RM p.93 Fig.8 for clock tree). So, basically, our problem was that we thought that PCLK1 was set to 36MHz by default. For later practice follow the clock tree and default initialization of clock registers.
(click to make larger)
21.12.2020: Sensor works using D6 interrupt and LD2 as a response.
TBD:
These are the documents and links we have used in the learning process. HC-SR501 PIR Sensor How HC-SR501 PIR Sensor Works & Interface It With Arduino - very informative.
HC SR501 PIR Sensor Datasheet.pdf PIR Motion Sensor.pdf
How to use HC-SR501 Motion sensor for Arduino with code - YouTube