stm32 witch pin PWM capable : datasheet? - arduino

I want to build a project with an STM32G070.
I need a couple of PWM pins.
I look at the datasheet and user manual, and I cannot find anyware if all pins of if only some are PWM capable and so, witch one it is.
I want to know because, if i look at the BluePill, not all pin are PWM.
Anyone can guide me ?

To answer the question - no, not all pins can be configured for PWM. However, most STM32s (including the STM32G070) have multiple timers, many with multiple channels which can generate PWM signals, and these can be mapped to many pins. So it's almost guaranteed that you'll find two spare pins that are not used by other peripherals, that you can use for PWM.
As mentioned, PWM signals are generated by timers. You can consult the reference manual for the STM32G070 to see which timers are available, and which ones have channels that can generate PWM signals. And you can reference the datasheet to see which pins they can be mapped to.
If I was designing a board, I'd create (e.g. in STM32CubeIDE) the crucial peripherals first (e.g. any SPI, I2C, UARTs, etc.) Then I'd see which pins are left over that could be used for PWM. There are bound to be several.

Related

Built-in led glowing on code of led on arduino mega

I had written a code on atmel studio for blinking a led on pin 13. After uploading the code with xloader mega's builtin led was blinking.
I uploaded fade code on my mega and the builtin led was blinking instead of led. What should i do?
I am using arduino mega 2560.
int main(void)
{
DDRB=0b00000000;
while (1)
{
PORTB=0b10000000;
_delay_ms(1000);
PORTB=0b00000000;
}
}
What you should do? Read the manual.
Please refer to https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf
Chapter 13.2.
The DDxn bit in the DDRx Register selects the direction of this pin.
If DDxn is written logic one, Pxn is configured as an output pin. If
DDxn is written logic zero, Pxn is configured as an input pin.
Working with registers doesn't make sense if you don't know what they do.
DDRB=0b00000000;
Gives you inputs only.
why would you use Arduino and try to program it without its conventional macros and functions?
If you are trying to blink an led or make it breath then use the Arduino IDE and its built-in functions analogWrite() to generate a pwm pulse for your led or any led on suitable pins which support analogwrite(). You shouldn't try to do any direct modifications on registers if you have no suitable knowledge, because your risk destroying your development kit and maybe burning some other stuff around. Please use your kit's schematics to spot the pins which support analogwrite() and then use the code in examples.
That way you will achieve your goal faster and without any issues.
TL/DR: you have to set 7th bit in DDRB to one.
In AVR ports are configured by bits in two registers: DDRx and PORTx.
When the corresponding bit in the DDRx register is set to one, the port is configured as output. And the corresponding bit in the PORTx register chooses which electrical level is output on the pin. If it is 0 then internal MOSFET shorts the pin to "ground" lane, and sinks current from external source. When the bit of the PORTx is one, then the pin is connected to "VCC", sourcing big amount of current enough to lit up a LED.
But if the pin is connected to something, what consumes too much of current, or the pin is shorted to GND or VCC (let's say you have a button connected and pressed), then output MOSFETS might be overloaded and damaged.
If the bit in DDRx is set to zero, then the pin is configured as input. If the corresponding bit in the PORTx is zero, then the pin has no internal connection to power lines, it is called "Hi-impedance" state, or Tri-state. It does not source or sink any current. So, if no external source of current is connected, then pin level is floating, influenced by electrical interference. Logical level is not detectable and can change occasionally. If you want to connect, for example, a button (between the pin and GND), then logical level will be defined only when button is pressed. When it is released, the logical level will be undefined.
But! If the bit in the PORTx is set to one, then internal MOSFET connects the pin thru a resistor (about 35 kOhm) to VCC line. This make the pin to source a little amount of current, setting its logical level to high. Therefore, if a button is connected, when it is released, then pin will have defined high level. This is called "pull-up resistor". When button is pressed, it will not short and damage the MCU, because current flowing thru the button is limited by the resistor, but the logical level will be defined low.
What if instead of button you have a LED connected to the pin? Very small amount of current will flow thru the LED, makes it barely glow.
Read more in the datasheet (chapter 13. I/O-Ports)

STM32DUINO and analogRead for stm32f103c8t6

I have custom board on which I can upload my code generated from platformio and as board bluepill_f103c8. And I can make led blink etc. but when I want to do analogRead it always returns 0.
I'm trying to read from PA8 pin.
In my setup I put that pin as INPUT_ANALOG, do I need to do something else in order to get the reading?
Voltage that's on pin is about 0.25V that I'm trying to read.
According to STM32F103 Datasheet, page 34, any of 3 onboard ADCs simply do not have the ability to connect to PA8. PA8 can only work as simple GPIO (default, reads only 0 and 1), or as USART1_CK, TIM1_CH1, MCO in alternative configuration.
Arduino can use it as PWM output, or software USART, but there is no way to get analog reading from it.
If you really need to read analog voltage coming to that line, you would have to modify your board and solder PA8 to one of PA0..PA7, PB0..PB1, PC0..PC5 and re-configure ADC to read from that line.
#TonoNam, regarding your problem: unless PA1 is permanently damaged, it is fully capable of working with ADC, so there is something wrong with initialization or reading procedure.
Reference the pinout diagram here https://wiki.stm32duino.com/index.php?title=File:Bluepillpinout.gif
analogRead will only work with the pins which have associated ADC channels.
So this is PA0 through PA7, and then PB0 and PB1, so I guess this is your issue.
Looks like PA8 is a PWM output.

Does a PIC 16197 Microcontroller have D/A converter?

I want to send out values with analog pins which would be read by analog pins of any other microcontroller.
It appears that you're referring to the PIC16F1619, all the related information that you can look for your requirements is inside the datasheet, I invite you to look at PIC16F1619 Web Page from Microchip and you will see all of the features and the current documentation to work with all of the peripherals included in this particular Microcontroller, however, according to the datasheet, the RA0 pin from this MCU has the feature to give an 8bit DAC output.
I hope this could help.

On NodeMCU or Arduino, what is the best rest state for a GPIO pin?

If a pin is unused, what should be its rest state?
I'm thinking gpio.INPUT makes sense, or maybe gpio.OUT set to gpio.LO, grounding the pin.
Is there a customary or preferred setting for unused pins?
For unconnected pins INPUT_PULLUP or OUTPUT. Using Pull-Up is better if there is any possibility that board layout will chance and someone connects this pin to ground/Vcc directly. It's better to sink small current to ground than short output pin to different logic level.
For connected pins INPUT (connection should be connected to LOW or HIGH level)

Communication Protocol for Transmitter Module

I am trying to figure out the communication protocol of the transmitter chip found inside an RC remote (FS-GT2B). Originally, I thought it was I2C but after some research it seems less likely because it is lacking some characteristic lines. The silkscreen says "SCK", "SCS" and "SDIO". Here's a picture of the chip's pinouts: . Can anyone offer some pointers as to what the communication protocol of this guy is?
Thanks!
The pins correspond to clock (SCK), chip select (SCS), and data input output (SDIO). You need to toggle the SCK pin in the appropriate way as you change or read the data on the SDIO pin. the SCS pin is likely for data direction (read or write).
There is no easy way to determine the protocol from a black box. Instead, you need to remove the RF shielding case to see the chip. A soldering iron and a solder sucker will do the job. Be careful not to overheat the circuit inside.
Use the number on chip to determine what kind of chip it is, then find the datasheet by searching the internet.
Once you have all that and write some code, this is appropriate place to ask questions about it.

Resources