Pages: 1 [2]   Go Down
Author Topic: Serial.read to char[9] buffer not working?  (Read 1884 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That TINYCORE serial code should work on a ATtiny2313.
Does this help, http://arduino.cc/forum/index.php/topic,139695.0.html ?

Are you sure the clock is set correct in hardware and software, so the baudrate is correct ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
I am not knowing everything, im just able to count ^^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay, got the serial read to work, and it seems to read the input, i wrote  little program that just activates a led if it reads a B, my attiny85 is sending in the format B40284028* and the led starts to flicker as it reads, so it seems to get the serial code just fine, but still its not doing anything else....maybe it wont complete the loop? i will test it and report back soon ^^ im getting near....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
I am not knowing everything, im just able to count ^^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i was still curios what the 2313 receives, because it didnt always react to my signal send over terminal, so i wrote a small code that just print what it receives:
Code:
void setup() {
Serial.begin(9500);
}
void loop()

   Serial.println(Serial.read());
}

it always receives this, evin if ther is nothing connectet to the input.
Code:
Kj
Kj
Kj

and if i send "hello world" i get
Code:
Kj

¡º
¡‚8C¡Š1C!j
j
j
j
j
Ój
j
j
j
MH0C¡j
j
LH1Sj
¦H1NSH1Š
¡¢9C¡Â1C¡ª2C¡Â1C¡ª1C!j
L“j
SH4C¡“j
Kj
Kj

the funny thing is, that it seems to send and receive the endline just fine.

im not shure if its a baudrate problem is, as the attiny 2313 is running at 8 MHz with a baud at 9600 and the monitor ist connected to its rx and tx pins ( uno board with disconnected 328)

it cant be the terminal, as i receive the data from the attiny 85 just fine!(also running at 8 MHz with 9600 Baud...)

i am realy out of ideas.... i even replaced the hardwareserial.cpp in the core files with the one from this post, (although there the problem was not compiling) and still nothing....
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can be explaned, but it takes three problems.

(1) You can't read something if nothing is available.
(2) You have to specify that it is a character, otherwise the type might be converted to an integer.
(3) A wrong baudrate could be the third explanation. Can you check again how the baudrate is set for a certain cpu clock.

Code:
void loop()
{  
  if (Serial.available() != 0)
  {
    Serial.print( (char) Serial.read());
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
I am not knowing everything, im just able to count ^^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay, i think i found the culprit, i used the attiny 2313 with internal clock set to 8 Mhz and i thought it would be perfekt, but i testet a little further with this code:
Code:
void setup() {
Serial.begin(9300);
}
void loop()

  if (Serial.available() != 0)
  {
    //Serial.print( (char) Serial.read());
    Serial.println("hallo welt,ja ich bin da!");
  }
  Serial.flush();
}

and guess what, with a baudrate set to 9600 my terminal just receives garbage. if i set it to at a value between 9300 and 9400, it receives the text just fine,but without the line end. so i guess the internal clock of the 2313 is not too acuarate and thats producing all the problems i got. most likly the final code for the project is completly fine, and its just that the 2313 is not receiving the data from the 85 correctly. though the internal clock of the attiny85 seems just fine.

anyway, i will try to add a 8 MHz to the 2313. but i dont know how to configurate the arduino bootloader to run at 8 MHz and use an external 8mhz crystal. read a lot about fuses, but found it quite CONfuseING smiley-lol, maybe i will figure it out.

thanks for all the help and your patience with me ^^
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This makes fuses a lot easier: http://www.engbedded.com/fusecalc/
Can you lower the baudrate to 1200 ? I don't use 9600 with the internal clock, but 1200.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
I am not knowing everything, im just able to count ^^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

lowering the baudrate doesnt help either u_u will go to my electronic store and get some crystals+ capacitors.
Logged

NJ, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1) What do you mean "my terminal"?
Are you talking about the arduino IDE serial monitor? or are you using something else like linux screen?

2) I suggest you test with a string that would help diagnose the problem, for example "000000" ( HEX 303030303030 ),
which  will produce the binary string (including  start and stop bits)  100110000010011000001001100000100110000010011000001001100000.
or even better "@@@@@@" (HEX  404040404040) 101000000010100000001010000000101000000010100000001010000000.
When you see the characters received you may better be able to determine if there is really a baud rate issue.
3) can you lower the baud rate even further like 300

4) Regarding size, RAM or flash?
Are you aware that the HardwareSerial is allocating a 16 byte input buffer AND a 16 byte output buffer?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
I am not knowing everything, im just able to count ^^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okay, so
1. yes i am refering to the arduino IDE Serial monitor, but putty gives me the same.
2. printing @@@@@@@ throws me something i cant even post as im not even able to write these letters smiley-lol and in binary it is something seemingly completly messy.
3. lowering the baudrate didnt help at all, same issue, even with 300 Baud.
4. no i am not aware of that, well not completly, i didnt know which size the inputbuffer would have, and i would preffer to use a "receive only" lib, but i am not as expierienced to just write my own or something like that. if i were, i would not try to use the arduino core, to write everything in a for me relativ simple way.

i got the crystals of 8 mhz here now and im trying to figure out how to set the fuses on the arduino to allow to use the external 8MHz crystal.

Am i right that i have to change something within the tiny corefiles so that i could make the bootloader set the right fuses?

oh, and i just found the some files, as far as i understand this, the bootloader hex files in the arduino/hardware/tiny/bootloaders are just the arduino bootloader for the specific clock settings, and the fuses are defined in the bords.txt, am i correct?

Code:
###########################################################################

attiny2313at8.name=ATtiny2313 @ 8 MHz

# The following do NOT work...
# attiny2313at8.upload.using=avrispv2
# attiny2313at8.upload.using=Pololu USB AVR Programmer

# The following DO work (pick one)...
attiny2313at8.upload.using=arduino:arduinoisp
# attiny2313at8.upload.protocol=avrispv2
# attiny2313at8.upload.using=pololu

attiny2313at8.upload.maximum_size=2048

# Default clock (slowly rising power; long delay to clock; 8 MHz internal)
# Int. RC Osc. 8 MHz; Start-up time: 14 CK + 65 ms; [CKSEL=0100 SUT=10]; default value
# Brown-out detection disabled; [BODLEVEL=111]
# Serial program downloading (SPI) enabled; [SPIEN=0]
# Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0]

attiny2313at8.bootloader.low_fuses=0xE4
attiny2313at8.bootloader.high_fuses=0x9F
attiny2313at8.bootloader.extended_fuses=0xFF
attiny2313at8.bootloader.path=empty
attiny2313at8.bootloader.file=empty2313at8.hex

attiny2313at8.build.mcu=attiny2313
attiny2313at8.build.f_cpu=8000000L
attiny2313at8.build.core=tiny
 

so i would just add another section for attiny2313 at 8 MHz with external clock, but which fuses do i need to change? and wahts these high,low and extendes fuses? thats still confusing me....
« Last Edit: March 22, 2013, 04:42:32 pm by darkmateria » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
I am not knowing everything, im just able to count ^^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AND SUCCSES, i just added another line to the boards.txt and the confusion about the fuses has been liftet as well, an guess what, everything works fine using an external 8 MHz colc, so it realy was the internal clock that wasnt correct. its not as neat to have an extra crystal built in to this project, but i gues its better then a non working one^^

Many thanks for all your help and time, i realy apriciate it!

when everything is done( that includes soldering of 48 realy tiny bicolor smd leds) i will post some pics for ya.

i must say i realy learned a lot along the way, so many thanks ;-D
Logged

Pages: 1 [2]   Go Up
Jump to: