ATMEGA328 RX & TX Problems! - Page 1
Forum section: electronics / general

author: Nikan
author_rank: Regular Contributor
timestamp: July 01, 2017, 07:03:59 pm
content: Hi Folks,I have a problem with my project.I have got an Arduino sending 1&0 to a bluetooth module which sends the data to an other module.Well my oscilloscope proves me, that I'm getting the data on the 2nd module, but im not able to read it.I have got a standalone atmega328 TQFP connected to the RX&TX pins of the 2nd module but it seems like the Atmega328 is not recognizing the data.I have connected the RX&TX to PB0 and PD7 which are both PCINT pins. They only havbe to be conected to PCINT pins, that should do the trick right???An other problem is, that I cant change the pins due to the reason, that I'have already soldered the µC to the board.So long story short:bluetooth module is recieving data.RX&TX conected to PB0&PD7Not able to see anything with the µC but with my oscilloscope!What should I do now?!?!Here is my code:#include<SoftwareSerial.h>Softwareserial mySerial(7,8); // already tried to change themvoid setup(){mySerial.begin(115200); // everything is set to 115200DDRB = 0x00000010;}void loop(){if(mySerial.available()){PORTB = 0b00000010;}}

author: alm
author_rank: Super Contributor
timestamp: July 01, 2017, 08:49:44 pm
content: Clock source? Asynchronous serial (UART) depends on the baud rate of the receiver and transmitter to be within 5% or so. If one of the sides is using a low quality clock source (like internal RC oscillator) or if the clock frequency is not a nice multiple of the baud rate, then they can be too far off. Not sure how this exactly works with a software UART. Try measuring the baud rate from both sides with your scope. If you set the device to output a continuous stream of capital U, then it should show up as a regular square wave on your scope, making it easy to measure the baud rate.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: July 01, 2017, 09:00:22 pm
content: I'm not sure what you're trying to do with the code you have posted there, but it is not actually accomplishing anything.You are initialising the SoftwareSerial library by telling it you want to receive and transmit on Arduino pins 7 and 8, which do indeed correspond to pins PD7 and PB0 on an ATmega328P, so that is correct.However, in setup(), you are then modifying the DDRB register to set PB4 (a pin you are not using for serial) as an output, and more importantly, settingall other port B pins as inputs. The SoftwareSerial library automatically configures the RX and TX pin modes for you, but after this you are re-setting the TX pin (PB0) as an input! So I am not sure how you are apparently receiving data at your Bluetooth module.Secondly, what you are doing in the loop() function there also doesn't do what you want - that is, trying to receive data? All you are doing there, by setting the value of PORTB, you are repeatedly enabling the internal pull-up resistor on pin PB1. This occurs because, as per above, you have all pins on port B apart from PB4 set to inputs. Setting the value of an input pin only changes the pull-up.I think you should refer to some example code for SoftwareSerial in the Arduino library docs.

author: Nikan
author_rank: Regular Contributor
timestamp: July 02, 2017, 01:39:55 am
content: Sorry, I am changing the output of port c NOT B, my bad... to see if I'm able to get any data from the BT module...I'll try to measure that, but I am using a 16MHz external on one side and 20MHz on the other side.

author: alm
author_rank: Super Contributor
timestamp: July 02, 2017, 09:32:43 pm
content: If DDRB/PORTB is replaced by DDRC/PORTC, then it should not directly affect the software UART, but it would still not turn on the LED. You set port C4 as output, but turn on port C2. Try it first by replacing if (mySerial.available()) by if (1) to make sure you are turning the LED on successfully.It is bad practice to modify pins you are not using, so DDRC = 0x10 should be written as DDRC |= 0x10, or more readable as DDRC |= (1 << 4). This will set the fourth bit to 1, and leaves the other bits untouched. If this confuses you, look up bit manipulation in C.

author: yamadanao
author_rank: Newbie
timestamp: July 03, 2017, 09:21:09 am
content: Here is thedate sheet of atmega328p,maybe it help you.