Click here to Skip to main content
15,886,772 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
Im working with EEPROM now, i send data though serial port to it, and EEPROM waits from data 24 bits, the first 8bits - EEPROM understand as address where to write sending data, the antoher 16bits - its what to write.
So im confused how make it happen in C# code.

Update:
Ok, im using AVR BASCOM to compile on mk, but problem not in bascom,
for exmaple, command inputbit will receive value from UART and assign it to variable
the Inputbin will wait for 3 bytes 
1 byte = address (dim as byte) 
2 bytes = data (dim as word) = 2 bytes 
' 2 bytes becouse word = 16bits
For exmaple i want to write "4001" to 25 memory cell in EEPROM.
Data_tx = 4001 
Addr = 25 

this numbers on binery are
SB OP address     data        not used 
 1  01 011001 0000111110100001 0000000 
         25           4001     dont care 


SB, OP = start bit and op code it equals 101 due to EEPROM datasheet, after them going my address which consist of 6 bits, then 2 bytes data that we want to write.(cuz i have 64x16 wire)
If i send for exmaple 1,
serialPort1.Write("\u0005");
and write the address in my AVR compiler( im using AVR BASCOM btw), for exmaple in Fifth memory cell, it will write 0000 0000 0000 0001 to 5th memory cell. But i need to not write address or data by my own on compiler code. I need to send it by Windows forms utility.
THerefore i need to send the address which equals 6 bits and address which equals 16 bits, its how i understand it

What I have tried:

private void button1_Click(object sender, EventArgs e)   // Here i send a data to MK
    {
        serialPort1.Write("\u0001");             // 5 bytes
        serialPort1.Write(Convert.ToString(0x05));     // 0005 hex
     }
Posted
Updated 8-Feb-17 22:48pm
v3
Comments
Ralf Meier 9-Feb-17 1:01am    
This is the same as in you other question.
I would suggest that you improve your question with advanced Information. What should you write to the SerialPort ? Explain it with an example ... I think you have not understood what you really should write to the Port to get an answer ...
JeezyWonder 9-Feb-17 1:20am    
updated, sir
Ralf Meier 9-Feb-17 2:03am    
If I understood it right you need to send 5 Bytes to your Serialport.
The Byyte-Content must be build like your example (above).
So ... I would first create a ByteArray with the required size.
Now write at Index=0 the value of SB, at Index=1 the value of OP, at Index=2 the Value of your adress, at Index=3 the High-Byte of your data (data / 256), at Index=4 the Low-Byte of your data (data or 255) and finally into the last Index the value 0.
Now write thsi ByteArray to the SerialPort ...

1 solution

C#
serialPort1.Write("\u0001");             // 5 bytes

No that is 2 bytes x00 and x01.
In your comments you say you want to send "4001" to 25 memory cell in EEPROM. Using hex notation would make this clearer:
C#
byte[] bData = new byte[]{ 0x40, 0x01 };
byte[] bAddress = new byte[] { 0x25 };
serialPort1.Write(bAddress, 0, 1);
serialPort1.Write(bData, 0, 2);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900