Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Creating variables with the address specified

Status
Not open for further replies.
yes possible .. like said in previous post in I2c read routine of slave device ignore address , take data. update that data to your variable




I think you do not understand my question
 
Last edited:

Ok, I think I understand. You want to update a value at a specified address on a different MCU but using I2C as the communication method.

It is possible but I2C isn't the best protocol because it is primarily intended to be used for input and output rather than linking autonomous systems together. You need to emulate a slave device on the second MCU and then pass it more than one byte. The first byte(s) would carry the address you want to write to on the slave and the next byte(s) would carry the data to be written to it. So you pass the location and the content as a multi-byte I2C transfer.

Brian.
 

Ok, I think I understand. You want to update a value at a specified address on a different MCU but using I2C as the communication method.

It is possible but I2C isn't the best protocol because it is primarily intended to be used for input and output rather than linking autonomous systems together. You need to emulate a slave device on the second MCU and then pass it more than one byte. The first byte(s) would carry the address you want to write to on the slave and the next byte(s) would carry the data to be written to it. So you pass the location and the content as a multi-byte I2C transfer.

Brian.

i want make variable with specified address in slave micro

I found my answer in CodevisionAvr for make variable with specified address using :

Code:
/* the integer variable "a" is stored
   in RAM at address 80h */
int a @0x80;

how make it, on Atmel Studio & how make in in windows ?
 

That code tells the compiler to locate "a" at the specific address 0x80 but it does it at the time the program is compiled and it can not be changed during program execution.

You can't send a command to the slave to tell it where to store a variable. The nearest you can do is create a space in RAM on the slave and pass it the address within that space and the value to store there. It requires that you use some kind of protocol to distinguish the address from the data as they could both be the same value. For example, as "a" is an integer (probably 2 bytes) and the address is probably 16 bits wide (again 2 bytes) you could send a fixed length I2C data packet that always has 4 bytes payload in the format aabbccdd where aabb is the address and ccdd is the data to store there. You would have to make sure 'aabb' was reserved RAM space in the target MCU.

Brian
 

i want make variable with specified address in slave micro

It is allways a bad concept trying to address a physical location at another device; this turns your code linked to this hardware is specific, and will also perhaps face to issues with the linker. The best approach is to create a record register instead, for example, if you want to write a byte 'val' to the address adr you will write to a variable, like that: R[adr]=val.
 

how make it, on Atmel Studio & how make in in windows ?

Atmel Studio uses GCC compiler, so you can place variable at specific location using gcc attributes:
Code:
int8_t __attribute__((section (".mySection"))) array[SIZE];

Section can be declared at project properties, or linker script.

But I still do not recommend you using direct physical addresses. As I advised you (not only I) earlier, use indexed addressing. Your master i2c device won't see any difference, but your slave device will be much easier, more reliable and less vulnerable.

I really wonder why do you need exactly physical mapping?
 

hi

agree with all of them, instead of I2C use RS232, easy to impleament & debug.
 

Hi,

Another aspect you need to take care:

If you use 8 bit interface...but want to change a multi byte variable...you have to take care about integrity of variable value.
I recomment to include some error detection in your protocol.
Then store the receiving data in an independent variable. On receive complete..check the integrity and if safe, then use an atomic acces to update the real variable.

Klaus
 

at first i check CRC Error and than use the input data
 

at first i check CRC Error and than use the input data

yes , like when you recieve data it will be in the form of frame for example
ID (some identifier | actual data | LRC or CRC | EOF

check for CRC/ LRC you need to create small algorithm for that CRC sent by transmitter mcu should be same at receiver side, impleament same algorithm both side.
if CRC calculated ok then and then only you take that data, if not then ask to resend the data
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top