Pins are not outputting STM32F103C6T6 - c

I am trying to get the mentioned board working with just a basic program to turn on an LED. I have FTDI pins Tx, Rx, VCC, and GND connected to A9, A10, 3.3, and GND of the board respectively. I am able to successfully upload the program to the board from Arduino IDE over Serial successfully (see below).
Using Parser : Raw BINARY
Interface serial_w32: 115200 8E1
Version : 0x22
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0412 (Low-density)
- RAM : 10KiB (512b reserved by bootloader)
- Flash : 32KiB (sector size: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
...
Wrote address 0x08002b98 (100.00%) Done.
Starting execution at address 0x08000000... done.
The PWR LED on the board is red while it's connected to the FTDI, however when I run the basic "Blink" program, the onboard LED (PC13) does not blink, I have also tried changing the pin in the code to digital output pins like PB12-PB15 with an LED and 220 ohm resistor connected between the output pin and GND but nothing happens.
Blink example code (2 = PC13)
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin PB1 as an output.
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
The main reason I can think of this happening is because I initially had the FTDI in 5V mode connected to the 5V pin of the board. That shouldn't be an issue though because then what would be the point of the 5V pin? If anyone has any ideas please let me know.
Pinout diagram

The Arduino IDE board library by stm32duino that was recommended in the tutorial was outdated. Using the library by ST Microelectronics to select my board in Arduino was the solution. The library index can be found here and should be added to the board manager. This allowed me to select the board STM32F1 Series. Now flashing my program onto the board works.

Related

STM32F4 DAC pins causes problems with adjacent GPIO pin

I have a strange problem that I dont understand. Please bare with me as this is a difficult problem to deconstruct. I will thus give as much information as I can with test cases and results I have found.
The problem:
I need to set PA6 LOW and then use the DAC. When the DAC is changed in a transient manner, the pin PA6 will not return to 3V when set to HIGH.
In other words, the DAC causes the upper voltage limit of PA6 to be 0.6-0.8V.
I have confirmed this with oscilloscope.
The following piece of code is called inside a task/thread and executed at 50Hz:
if (enable == 1)
{
HAL_GPIO_WritePin(PROPULSION_ENABLE_GPIO_PORT, PROPULSION_ENABLE_GPIO_PIN, GPIO_PIN_RESET);
HAL_DAC_SetValue(&PropulsionModule_DAC, PropulsionModule_DAC_CHANNEL, DAC_ALIGN_12B_R, PropulsionData.propulsionSetPoint_12bit);
}
else
{
HAL_GPIO_WritePin(PROPULSION_ENABLE_GPIO_PORT, PROPULSION_ENABLE_GPIO_PIN, GPIO_PIN_SET);
HAL_DAC_SetValue(&PropulsionModule_DAC, PropulsionModule_DAC_CHANNEL, DAC_ALIGN_12B_R, 0);
}
Setup and environment
STM32F4 Discovery board
FreeRTOS configured with threads, queues and everything else works as expected
I have a single DAC set up on DAC_channel_2 (PA5) and a GPIO_output (PA6).
I also have these peripherals enabled, CAN bus, UART, several GPIO's, etc. Please see attached picture
Findings:
When I change the PA6 pin to PC4 (the adjacent pin) the problem goes away
When I change DAC_channel_2 to DAC_channel_1 the problem goes away
I flashed the code to two other brand new, out of the box, boards with the same errors.
Once PA6 is faulty and its high state is at 0.6V, resetting the microcontroller will reset the pin PA6 and PA6 will return to 3V in its HIGH state.
Any help would be greatly appreciated.
I found the problem. The problem is the MEMS chip on the discovery board. It is vitally important one realizes that not all pins on the discovery board are usable.
Refer to the first link below from Page 22 on which pins are available. Please note that some of the pins that are "not free" can still be used. See the application notes on each of the chips on the board in the second link.
Link 1: https://www.st.com/resource/en/user_manual/dm00039084-discovery-kit-with-stm32f407vg-mcu-stmicroelectronics.pdf
Link 2: https://ucilnica.fri.uni-lj.si/pluginfile.php/29604/mod_resource/content/1/en.DM00039084.pdf

Sparkfun SC16IS750 interrupt pin IRQ not working

I am facing problems using sc16is750 breakout board. I want to use the interrupt method mentioned in the datasheet. According to which, the IRQ pin should be active low whenever Rx or Tx pins are active, and an Interrupt should be generated.
But the IRQ pin remains high nonetheless. I have set up an external 1k ohm pull-up resistor as mentioned with 3.3v VDD.
My goal is to use vk16e gps module through spi pins on an arduino uno. I have set up the low interrupt on digital pin 2 and it is working fine. If I manually connect this pin to the ground, the gps data appears successfully. But not with the IRQ pin.
I had a similar issue. Finally I found out that the interrupt pin on the breakout board is not connected to the 2kOhm IRQ pull up.
I added a white wire and now it works fine.

Reading a Tx from a barcode scanner with a Arduino Mega 2560 - RS232

For the past couple of days i have been trying to create a program which reads from a Tx of barcode scanner.
I have tried a bunch of different things such as different programs but also different scanners.
A sample program that i wrote is for example:
#include <SoftwareSerial.h>
SoftwareSerial mySerial (50, 51);
unsigned char incomingByte;
void setup ()
{
Serial.begin (9600);
mySerial.begin (9600);
Serial.println ("begin initial Serial!\n");
}
void loop ()
{
while(mySerial.available () > 0)
{
incomingByte=mySerial.read ();
Serial.print (incomingByte,HEX);
}
Serial.println ();
}
At this time i can not provide a proper connection diagram (will when i have a chance), but the arduino MEGA 2560 is connected with 3 wires to the barcode scanner, A Tx (pin 50), Rx (pin 51) and GND
background info on transmitted data:
startbit: 0x02
stopbit: 0x03
Ultimate goal:
Scanner scans barcode, arduino reads the datastream and sends a output when it recognizes a code.
How do i achieve the ultimate goal?
Thanks in advance!
Arduino 2560 pin 50 and 51 are TTL level signals. You need to provide a RS-232 driver to invert and level shift the signal.
An example driver is MAX232CPE.
http://www.surplus-electronics-sales.com/index.php?main_page=product_info&cPath=15&products_id=828&gclid=CJv7vNWim8oCFYOEaQodSjQDFQ
Also, softwareserial supports an option to invert the logic level. From the Arduino page:
inverse_logic: is used to invert the sense of incoming bits (the default is normal logic). If set, SoftwareSerial treats a LOW (0 volts on the pin, normally) on the Rx pin as a 1-bit (the idle state) and a HIGH (5 volts on the pin, normally) as a 0-bit. It also affects the way that it writes to the Tx pin. Default value is false.
Warning: You should not connect devices which output serial data outside the range that the Arduino can handle, normally 0V to 5V, for a board running at 5V, and 0V to 3.3V for a board running at 3.3V.
Arduino SoftwareSerial Reference page

Max485 chip not working on 3v3 logic but able to work on 5v arduino pin even if only connected through my finger

I recently figured out how to reprogram the rfbees from seeedstudio. (a 3v3 xbee format rf module with onboard atmega168)
I want to port my existing DMX circuit to the rfbee.
I'm using a Max 485 chip to create dmx signals using this circuit http://fritzing.org/projects/arduino-to-dmx-converter/
This works perfectly on my arduino mega at 5v, however I've uploaded the same sketch to the rfbee but not getting any luck.
I realize the rfbee's pins only output 3v3 logic and the max485 is supposed to be 5v.
However, the 5v pin on the mega can still run the Max485 even if it is brought down to approx 3 volts by using three 220ohm resistors as voltage divider. I can also apparently drive the max485 by holding the 5v arduino pin with one hand and touching the input pin of the Max 485. The chip also seems perfectly happy having its Vin connected to the Mega's 3v3 pin instead of 5v.
My question is this, is there an electrical difference between these last approaches versus the clean 3v3 I'd be getting from the rfbee?
I'm using identical code on both devices with an LED to verify heartbeat. As far as I'm aware the pin I'm using (pin 5) is a pwm pin on both devices, http://www.seeedstudio.com/wiki/index.php?title=RFbee_V1.1_-_Wireless_Arduino_compatible_node .
I'm at a bit of a loss to know to check next, I've tested the output on pin 5 of both devices with an led (no oscilloscope unfortunately), both showed the same brightness and that it was an oscillating signal.
Code posted below.
#include <DmxSimple.h>
const byte DMX_RGB_CHANNELS[]={2, 3, 4};
const byte DMX_OUT_PIN=5;
int led = 13;
void setup() {
pinMode(led, OUTPUT);
DmxSimple.usePin(DMX_OUT_PIN);
DmxSimple.maxChannel(6);
}
void loop() {
digitalWrite(led, HIGH);
DmxSimple.write(DMX_RGB_CHANNELS[0], 255);
DmxSimple.write(DMX_RGB_CHANNELS[1], 255);
DmxSimple.write(DMX_RGB_CHANNELS[2], 255);
delay(200);
digitalWrite(led, LOW);
DmxSimple.write(DMX_RGB_CHANNELS[0], 0);
DmxSimple.write(DMX_RGB_CHANNELS[1], 0);
DmxSimple.write(DMX_RGB_CHANNELS[2], 0);
delay(200);
}
Finally figured it out, for some reason the atmega was running at half speed therefore the DMX baud rate was wrong. I was able to change the clock speed from 16MHz to 8Mhz in the boards.txt of the arduino compiler. Works now and the Max485 and RFbee seem to be working fine off just two AA batteries. It's been a long week!

Arduino Uno PWM pins conflict

I built this motor shield based on the L298N chip to control two motors of a tank. It uses pins 5 and 6 for one motor, and pins 10 and 11 for the other.
While trying to add a TSOP 4838 in order to control the tank with an IR remote I noticed that moving the motor on pins 10/11 in reverse only works at full speed - that is, a HIGH (255) value on pin 11. Anything below that value doesn't output anything on pin 11 (measured voltage on those pins is 0 V).
For the remote I use this library. The IR receiver is connected on pin 2 (but the pin doesn't matter). The problem is the library code itself. The line that enables IR listening irrecv.enableIRIn(); is what is causing the problem. I learned that there is a conflict of internal Arduino timers and the pins used for PWM by the shield.
This is the code to power the motor in reverse:
#include <IRremote.h>
// IR receiver configuration
const int irPin = 2;
IRrecv irrecv(irPin);
// Motors configuration
const int mLeftPin1 = 10;
const int mLeftPin2 = 11;
const int mRightPin1 = 5;
const int mRightPin2 = 6;
void setup()
{
// Start IR
irrecv.enableIRIn();
// Setup motors
pinMode(mLeftPin1, OUTPUT);
pinMode(mLeftPin2, OUTPUT);
pinMode(mRightPin1, OUTPUT);
pinMode(mRightPin2, OUTPUT);
// Move left motor in reverse, slower speed
analogWrite(mLeftPin2, 100); // This works only with 255 instead of 100
digitalWrite(mLeftPin1, LOW);
}
Now, I found here that the pins used by the timers on Arduino Uno are:
Pins 5 and 6: controlled by Timer0
Pins 9 and 10: controlled by Timer1
Pins 11 and 3: controlled by Timer2
So my questions are:
Why does the shield in the instructable use pins 10 and 11 for PWM ? They correspond to 2 different timers. Why not 9 and 10?
In order to use the IR along with the motor shield, what timer should I configure the IR library to use?
If the answer is 2, a line should be uncommented in IRremoteInt.h. I am guessing the Uno would take the else branch at line 68, although only timer1 and timer2 are there. I wonder why timer0 couldn't be used for the Uno.
Although I'd like to leave cutting traces and resoldering as a last option, another possibility would be to change the pins used by the shield, but which? And I am guessing this would also be paired with configuring the timers to PWM on other pins than default, but I don't know anything about timers/interrupts and my knowledge of Arduino and C is limited.
I made this a long question, because I want to learn not just solve the problem, so feel free to explain more than what is asked.
While looking up for a solution I also found other conflicts to keep in mind when using PWM or timers:
Timer0 is an 8-bit timer, it can hold a maximum value of 255. It is used by delay() and millis(), so there are consequences when messing with it
Timer1 is a 16-bit timer, it can hold a maximum of 65535 (an unsigned 16-bit integer). The Arduino Servo library uses this timer
Timer2 is an 8-bit timer used by the Arduino tone() function
And, of course, the IRremote library uses TIMER_RESET, so depending on which timer it uses it can conflict with the associated pins.
Not all hardware is designed in the best way. Using 10 and 11 is indeed wasteful because it requires two timers.
2/3. Ideally you will use a timer that is not Timer0. Here's some more details on timers/interrupts:
The Arduino chip (328P) has three timers. Each timer can be used for multiple uses, however it is important to note that you can only have one timer interrupt enabled for each timer.
Take Timer0 for example. It interrupts in order to generate the proper delays for the delay() and delay_us() methods. It also is used for the PWM outputs on pins 5 and 6. This can happen because the PWM outputs don't use a timer interrupt, they use separate output compare modules.
Now looking specifically at your problem, it should work fine, even though you have a PWM output using timer2, the PWM does not take an interrupt on timer2 so the IR library should be free to use that interrupt. However, looking into the IR library code, we see this piece of code:
ISR(TIMER_INTR_NAME)
{
TIMER_RESET;
It appears that every time it interrupts, it resets the timer count. This could be why your PWM output is not working properly. The output compare module is waiting for a certain tick count, and it never reaches that.
As to why it somehow works at 255, we can take a look at the analogWrite code:
void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (val == 0)
{
digitalWrite(pin, LOW);
}
else if (val == 255)
{
digitalWrite(pin, HIGH);
}
So by writing 255, the analogWrite code ignores the whole PWM and output compare thing, and just writes the pin high.
Finally, as to solving your problem, I would personally go the route of not using pins 11 and 3 (timer2). Yes it will require a small rewiring, but that way you can free up timer2 for the IR library to use.
Alternatively, you could poke around the IR library and try to make it work without resetting the count.
Pay attention to the board used, if you use Arduino Uno, then the code responsible would be: // Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, etc
else
//define IR_USE_TIMER1 // tx = pin 9
define IR_USE_TIMER2 // tx = pin 3
endif
I had the same problem with a prebuilt L298 V2 motor shield.
The pins were marked like this on the shield:
Motor1: pin 3 and 5
Motor2: pin 6 and 9
I use PIN10 instead of 3 and using a small workaround: I put a wire from PIN10 to PIN3 on the SHIELD.
My project was to control my robot with a SAMSUNG TV remote control.

Resources