Atmega2560 Uart Communication

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone!
İs there any way transmit more than 8 or 9 bit from uart data packet ?

Newbie Mbed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Probably not, since the register can only hold so many bits....why do you need to & how many bits do you want to send?

 

It's fairly simple to bit bang a uart Tx format...then you can have as many bits as you want

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jul 26, 2019 - 07:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thx for your reply!
İ want send 28 bit to the slave and slave response 14 bit reply back to me With no stop bit between 8bit or more than.

One packet all of frame. How can i send this? Can you help me ?

Newbie Mbed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

28 bits fits int 4 bytes (32 bits total) so why don't you just send 4 bytes "normally" (8 bit) then extract the 28 you are interested in. Similar 14 bits fit into 2 bytes (16 bits).

 

I suppose you could say that 28 and 14 are exact multiples of 7 so maybe you just want to send 4 or 2 frames in 7 bit format?

 

How much control do you have over the slave anyway - is it a fixed device who's behaviour can't be changed or can you reprogram it to accept/send the data in an agreed format?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

İt is fixed device i cant change it bit stream. Only reply me when im transmit 28bit packet. Reply had 14 bit.

Actually it is running manchester coding bit stream. Manchester code event = if you want sende "1" logic bit you must transmit "01" or your want "0" logic bit must transmit "10".

So i will send 28 bit manchester coded bit stream, slave reply to me 7 bit which manchester coded 14 bit.

i transmit successed 28 bit stream on serial1 to my slave. Slave recognize my code and it reply back to me. I saw the reply on logic analyzer but cant recognize my chip.

 

Here is my bit stream

 

Long bit stream is my TX short is RX.

 

  Serial.begin(9600);
  Serial1.begin(83333);
  UCSR1C |= (1 << UMSEL11) | (1 << UMSEL10);

 

Serial1 baud rate approximetly 333333 Hz bit change speed every 3 us.

 

 

Newbie Mbed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A.sevincik wrote:

İt is fixed device i cant change it bit stream. Only reply me when im transmit 28bit packet. Reply had 14 bit.

Actually it is running manchester coding bit stream. Manchester code event = if you want sende "1" logic bit you must transmit "01" or your want "0" logic bit must transmit "10".

So i will send 28 bit manchester coded bit stream, slave reply to me 7 bit which manchester coded 14 bit.

i transmit successed 28 bit stream on serial1 to my slave. Slave recognize my code and it reply back to me. I saw the reply on logic analyzer but cant recognize my chip.

 

Here is my bit stream

 

Long bit stream is my TX short is RX.

 

  Serial.begin(9600);
  Serial1.begin(83333);
  UCSR1C |= (1 << UMSEL11) | (1 << UMSEL10);

 

Serial1 baud rate approximetly 333333 Hz bit change speed every 3 us.

 

 

  UCSR1C |= (1 << UMSEL11) | (1 << UMSEL10);

 

This code Master SPI mode in Uart

 

Newbie Mbed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

there is an Atmel app note that discusses manchester coding/decoding, have you see it?  It includes code in the note as well.

Here it is: http://ww1.microchip.com/downloa...

 

You may find this helpful, uses a bit-bang method: https://github.com/goldsborough/...

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Fri. Jul 26, 2019 - 01:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thx for your reply Jim 
I m trying your attachment but these codes baud rate not require for  my system speed. I cant reached 3 us bit toggle timing. I was try Atmega32u4 and arduino Mega(Atmega 2560(not compatibility)).
 

Newbie Mbed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A.sevincik wrote:
. I cant reached 3 us bit toggle timing.

You should be able too, if your system clock is fast enough, 16 - 20 MHz!  You will need to adjust the timer and bit timing values to reach the speed desired.

For example, with 16MHz clock, baud of 333333, timer tick /1, and bit time is 48 and half bit time is 24.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I wrote both a manchester encoder & decoder for 32bit  packets.  Since both were in assembler & "tight" they could work at very high speeds.  The decoder used a state machine to resync the reception upon bit loss. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

I wrote both a manchester encoder & decoder for 32bit  packets.  Since both were in assembler & "tight" they could work at very high speeds.  The decoder used a state machine to resync the reception upon bit loss. 

 

 How did you do that ? 
You can explain it ? 

Newbie Mbed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You don't want to use a UART to send Manchester encoding.  The UART is a hardware device that only works with 8 bits that are framed with start and stop bits in order to maintain data integrity.  And while it is true that you can reprogram the UART to do 7 bits and two stop bits, it would be unwise to do so because then your system would be different from 99% of all the other UART systems in the world that is using 8/N/1 formatting.  Having your system be different from everyone else's for no reason than because you can is 20th century mentality.

 

Now it may be possible to "mickey mouse" a set of parameters that will make a UART do Manchester encoding.  But it would take too much time to construct and debug, and it would take way too much time for any technician that was trying to repair or reconfigure your device in the future.  And when the cost of the time for the engineer to decipher your "special" format exceeds the cost of a new unit, then your customers will buy a new unit.  Most likely they will not buy it from your company.  Engineer time costs about $80 an hour.

 

In telecommunication and data storage, Manchester code (also known as phase encoding, or PE) is a line code in which the encoding of each data bit is either low then high, or high then low, for equal time. It is a self-clocking signal with no DC component.  It is not 01 for logic 1 and 10 for logic 0!

 

Since your shortest interval is about 3 microseconds, then you will need to encode this format in AVR assembler language for precision and reliably. With a 16MHz clock you have 48 system clock cycles to acquire the next bit, format it, and store it.  Plenty of time for someone with a little AVR assembler experience.