atmega128: how to make the 9-bit 0 ?

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

hello, 

 

master : atmega128

slave atmega16

AS7

 

i have a small question, the TXB8 bit (for 9-bit mode).

if it is "1" the following byte is the address

if it is "0" the following byte is your data

 

how i can make it "0"

 

thanx in advance

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

Why are you using 9 bit mode? Is this MPCM with multiple slaves?

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

how i can make it "0"

See the data sheet for the micro. For the ATmega328, the data sheet dated 2013 has it in Section 20.6.2  "Sending Frames with 9 Data Bit".

Mike

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

yes 20 till 30 slaves, 

i'm gonna check the  ATmega328 datasheet.

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

i found the  "Sending Frames with 9 Data Bit" on   Section 19.6.2

 

i already read this part before, the give a example what i don't really understand, specially the part underlined part.

 

void USART_Transmit( unsigned int data )

{
/* Wait for empty transmit buffer */
while ( !( UCSRnA & (1<<UDREn))) )
;
/* Copy 9th bit to TXB8 */
UCSRnB &= ~(1<<TXB8);

if ( data & 0x0100 )
UCSRnB |= (1<<TXB8);

/* Put data into buffer, sends the data */
UDRn = data;
}

 

Last Edited: Sun. Feb 23, 2020 - 03:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i found on the net a better explanation for the code above (who's comming from the datasheet)

 

void USART_Transmit (unsigned int data)
{
//Wait until the Transmitter is ready
while (! (UCSRA & (1 << UDRE)) );

//Make the 9th bit 0 for the moment
UCSRB &=~(1 << TXB8);

//If the 9th bit of the data is a 1
if (data & 0x0100)

//Set the TXB8 bit to 1
USCRB |= (1 << TXB8);

//Get that data outa here!
UDR = data;
}

 

Last Edited: Sun. Feb 23, 2020 - 03:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I fear you have misunderstood the purpose of "9 bit mode". You aren't really sending 9 bit data. The 9th bit is simply a flag to say either "the other 8 bits here are simply data" or "the other 8 bits are a device address (0..255) to pick which of the 256 possible slaves should now receive the following bytes of data which will the have the 9th bit= 0"

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

no, that is clear to me.

the original question was, how to make the TXB8  "0".

now i know that it goes like this:

UCSRB &=~(1 << TXB8);

but there is 1 thing what i still don't understand,

how the slave sends data back to the master ?

 

thanks for your help.

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

trixo wrote:
how the slave sends data back to the master ?

 

That depends TOTALLY on how the slave is programmed! Who created that program? That is the person you must ask.

 

One thing you MUST consider however. You cannot have different settings for receive and transmit. Just as both must have the same baud rate, the same parity setting, and such, so must both use or not use 9 bit data format.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sun. Feb 23, 2020 - 07:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i gonna make the slave by my self smiley

 

i'm happy all ready that the RS485 is working with a MAX485,

now the next step.

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

9bit mode looks good, but the problem you might find is getting a PC to talk it. Why would you want a PC to talk your protocol? Testing.
I’d suggest use an 8bit protocol like modbus.

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

you might find is getting a PC to talk it.

The problem is the chip talking to the PC, the other way around is "easy".

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

MaxLinear UART have

XR21B1420 - MaxLinear

Enhanced 1-Ch Full-Speed USB UART

[third paragraph]

...

... and optional multi drop (9-bit) mode simplify both hardware and software in half-duplex RS-485 applications.

 

...

[Application tab, download driver]

9-bit (multi-drop) mode is apparently in the Windows driver.

 


due to https://www.avrfreaks.net/forum/ch340g-ic-vendor#comment-2115341

 

"Dare to be naïve." - Buckminster Fuller

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

i never said that i want to talk whit a PC indecision

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

Sure, but how will you test your system?

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

the master is a atmega 126, and the slave is a atmega 16.

the send data to each other, that is it.

there are 20 slave's, and 1 master.

10 off them have 24 times a IR LED     (10 x 24 = 240 IR leds)

10 off them have 24 timer a IR sensor (10 x 24 = 240 IR sensors)

the LED's and the sensors make a scanner to scan a object,  the scanner will be 240 x 10 mmm (the pitch) = 2400 mm

the object moves and every 10 mm i gonna make a scan. and that for a object from 3 mtr.

that gives 300 x 300 (vert. X hor.) = 90000 "bits"

 

so first i have to send from the master to the slave, a kind of a bittrain to switch on the IR LED/sensor combination one by one, and store the data in to the RAM off the atmega 16.

then i have to send the data from the slave to the master, to do some calculations and steer stepper drivers.

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

trixo wrote:

the master is a atmega 126...

 

Typo I guess.

 

 

trixo wrote:

that gives 300 x 300 (vert. X hor.) = 90000 "bits"

...

then i have to send the data from the slave to the master, to do some calculations and steer stepper drivers.

 

90,000 bits is 11k250 bytes. The mega128 only has 4k; are you using external RAM?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

That said, 9-bit mode will do what you want.

 

Each slave is assigned an address (DIP switch on the board?) and when idle sits with 9-bit mode enabled. The master sends a 9-bit byte with bit 8 set containing the address of the slave it wants to talk to. All slaves receive the address byte and check to see if the message is addressed to them.

 

The addressed slave does what it needs to do and optionally returns the data. All other slaves go idle waiting for the next address byte.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

of course atmega 128 frown

address is fixed programmed in the RAM from the atmega 16

yes i'm gonna use a externe RAM whit SPI (23LC1024)

 

i'm not sure what you means with this:

and when idle sits with 9-bit mode enabled

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

Have a read of 'Multiprocessor Communication Mode' in the datasheet.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Forgot about the 80C51 UART as this has 9-bit and multi-processor.

There are very inexpensive USB 80C51 (WCH); there are Microchip's USB 80C51 (by acquisition of Atmel and, IIRC, an earlier acquisition)

 

https://github.com/Blinkinlabs/ch554_sdcc/blob/master/include/debug.c#L168

due to :

 

AN_4346 Program Examples for 8051 UART (search for "mode 3")

 

edit :

original is Intel MCS-51

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Wed. Feb 26, 2020 - 07:26 PM