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.

Atmega 32 programming for data transfer with clock synchronisation.

Status
Not open for further replies.

vinkad999

Newbie level 5
Joined
Feb 11, 2012
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
Hi,I am Vinod Kumar K V pursuing final year graduation.As my academic
project is based on Atmega 32 microcontroller i need to make the code
for data transfer with clock synchronisation.Suppose if i send the
data as DE801234 where DE is the satellite command and 80 represents
the data command and the remaining 1234 should generate pulses as 1
comes means it should generate 0001{binary format of one} with clock
and 2 means it should generate 0010 with clock and so on for 3 and 4.I
need your kind support regarding this .How can i write the code for
this .I will be waiting for your fruitful feedback.
 

vinkad999 said:
the remaining 1234 should generate pulses as 1
comes means it should generate 0001{binary format of one} with clock
and 2 means it should generate 0010 with clock and so on for 3 and 4.
Could you please elaborate? What does "with clock" mean? In which clock you are referring to? And what kind of synchronization would that be?
 

Could you please elaborate? What does "with clock" mean? In which clock you are referring to? And what kind of synchronization would that be?
Internal clock as i am using it in my project [internal 1Mhz].Here clock means for raising edge the data must be sampled.Suppose for low to high transition of a clock the bit 0 or bit 1 must be sent.Suppose if i send 1 in my data .For four clock pulses ,data 1 [0001 in binary] should be outputted.Here bit 0 is 1 for first clock pulse that should be outputted,for second clock pulse bit 1 must be outputted and so on bit 3.
 

vinkad999 said:
Internal clock as i am using it in my project [internal 1Mhz].Here clock means for raising edge the data must be sampled.Suppose for low to high transition of a clock the bit 0 or bit 1 must be sent.Suppose if i send 1 in my data .For four clock pulses ,data 1 [0001 in binary] should be outputted.Here bit 0 is 1 for first clock pulse that should be outputted,for second clock pulse bit 1 must be outputted and so on bit 3.
So you want each time the system clock toggles, to buffer your data out is that it? But how are you going to do that? How are you going to catch up with your system clock?
Is there any standard you want to follow like SPI or I2C? Or do it by software of your own?
You could do this with the help of a timer interrupt. In this way you will synchronize the data, obviously with slower clock than your oscillator's.

But in any case, you must give a more detailed description. You are going to communicate with what? Is your MCU master or slave? Please give a full application scenario, otherwise members will not be in position to help you even if they want to.

Alexandros
 

So you want each time the system clock toggles, to buffer your data out is that it? But how are you going to do that? How are you going to catch up with your system clock?
Is there any standard you want to follow like SPI or I2C? Or do it by software of your own?
You could do this with the help of a timer interrupt. In this way you will synchronize the data, obviously with slower clock than your oscillator's.

But in any case, you must give a more detailed description. You are going to communicate with what? Is your MCU master or slave? Please give a full application scenario, otherwise members will not be in position to help you even if they want to.

Alexandros

I am going to communicate with rs232 and i am sending the data from hyper terminal to the microcontroller through rs232.Is that possible with system clock or can i use external clock??.I am sending the commands from hyperterminal .There are three types of commands i am sending.Namely Level,Pulse and Data command.Data command is recognized by the command DE80 followed by the data[for example:DE801234 OR DE802567].
 

vinkad999 said:
I am going to communicate with rs232 and i am sending the data from hyper terminal to the microcontroller through rs232.Is that possible with system clock or can i use external clock??.I am sending the commands from hyperterminal .
OK now we have some usuful information! :smile:
No need for external clock. Let us first post the datasheet to have our reference.
http://www.atmel.com/Images/doc8155.pdf

So in page 172 in table 19-9 you can see that you have a maximum baudrate of 115200 for fosc=1MHz, and only if you use double speed.
Keep in mind that from the MCU side you need to have the exact same settings with hyperterminal to make it work (baudrate, stop bits, etc).
In chapter 19 (USART), several examples are given for USART initialization, transmit and receive. You can first follow these examples to easilly establish a valid communication with hyperterminal. I suggest to carefully read the whole chapter in any case.

As for hardware, you need to use an RS-232 driver like MAX232.
**broken link removed**
http://en.wikipedia.org/wiki/RS-232

Also the below references will help you to get you started with code and hardware.
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=45341
https://www.edaboard.com/threads/216000/
https://www.edaboard.com/threads/238236/#post1018972
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=48188
https://www.edaboard.com/threads/225604/
https://www.edaboard.com/threads/228501/


vinkad999 said:
There are three types of commands i am sending.Namely Level,Pulse and Data command.Data command is recognized by the command DE80 followed by the data[for example:DE801234 OR DE802567].
You don't need something special for this. If you manage to send a single character succesfully, then the road is open to proceed as planned! ;-)


Hope it helped,
Alexandros
 

OK now we have some usuful information! :smile:
No need for external clock. Let us first post the datasheet to have our reference.
http://www.atmel.com/Images/doc8155.pdf

So in page 172 in table 19-9 you can see that you have a maximum baudrate of 115200 for fosc=1MHz, and only if you use double speed.
Keep in mind that from the MCU side you need to have the exact same settings with hyperterminal to make it work (baudrate, stop bits, etc).
In chapter 19 (USART), several examples are given for USART initialization, transmit and receive. You can first follow these examples to easilly establish a valid communication with hyperterminal. I suggest to carefully read the whole chapter in any case.

As for hardware, you need to use an RS-232 driver like MAX232.
**broken link removed**
http://en.wikipedia.org/wiki/RS-232

Also the below references will help you to get you started with code and hardware.
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=45341
https://www.edaboard.com/threads/216000/
https://www.edaboard.com/threads/238236/#post1018972
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=48188
https://www.edaboard.com/threads/225604/
https://www.edaboard.com/threads/228501/



You don't need something special for this. If you manage to send a single character succesfully, then the road is open to proceed as planned! ;-)


Hope it helped,
Alexandros
I have established the communication using the baud rate of 4800bps with 1mhz internal clock.Now how can i send the data that should synchronize with the clock.I need the code for that.
 

vinkad999 said:
Now how can i send the data that should synchronize with the clock.I need the code for that.
I don't have the slightest idea of what you mean. The data are already synchronized. If you need to send those data at specific periods of time, then as suggested in earlier post, you can use a timer.
 

Sir i need your help.I need to contact you regatding this so that i can i tell u properly.Please reply with your mobile number so that i can i discuss with you.Its my request to reply with your contact number.I am new to this atmega 32 programming.
 

Please post whatever you like inside forum. You will get more answers in this way. ;-)
But first of all please give the application scenario. It seems like you don't know well what you need to achieve.
I posted a lot of references but you replied in less than 10 minutes to get extra help. Did you even opened those references?
Code is included in several of them.

Alexandros
 

Sir simple if i sen data command as DE801234 .DE80 is not a problem but 1234 should be outputted as in binary format as 0001[i.e 1]with 4 clock pulses for each and so on for 2[0010],3[0011],4[0100].

---------- Post added at 00:07 ---------- Previous post was at 00:03 ----------

Sir i satellite communication there will be a test systems .Before onboarding any system that needs to be tested .So test systems is used to take the responses of each system to rectify the corectness of the system.So we give the commands as data,level,pulse.
 

vinkad999 said:
simple if i sen data command as DE801234 .DE80 is not a problem but 1234 should be outputted as in binary format as 0001[i.e 1]with 4 clock pulses for each and so on for 2[0010],3[0011],4[0100].
OK, I'll give you code for that a bit later.


vinkad999 said:
Now how can i send the data that should synchronize with the clock.I need the code for that.
By reviewing this thread again, maybe you mean USART synchronous mode?
 

yes.I need the code for the data transfer that should synchronize with the clock.
 

View attachment ddddd.txtSir i satellite communication there will be a test systems .Before onboarding any system that needs to be tested .So test systems is used to take the responses of each system to rectify the corectness of the system.So we give the commands as data,level,pulse.
 

vinkad999 said:
simple if i sen data command as DE801234 .DE80 is not a problem but 1234 should be outputted as in binary format as 0001[i.e 1]with 4 clock pulses for each and so on for 2[0010],3[0011],4[0100].
OK I assume that you are using a function to send serial data, let's call it send_char(), because I don't know the actual name you are using.
Now the function that sends the four bits should look like this:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void send_4_bit (unsigned char dec_ascii)
{
  unsigned char dec = (dec_ascii & ~'0');
 
  if (dec & 8)
    send_char('1');
  else
    send_char('0');
 
  if (dec & 4)
    send_char('1');
  else
    send_char('0');
 
  if (dec & 2)
    send_char('1');
  else
    send_char('0');
 
  if (dec & 1)
    send_char('1');
  else
    send_char('0');
}



If you want to send DE801234 like your example, then the code would be:


Code C - [expand]
1
2
3
4
5
6
7
8
send_char('D');
send_char('E');
send_char('8');
send_char('0');
send_4_bit('1');
send_4_bit('2');
send_4_bit('3');
send_4_bit('4');



Please use this code and post back the results.


vinkad999 said:
I need the code for the data transfer that should synchronize with the clock.
I haven't used synchronous mode, but according to the datasheet you need to set UMSEL bit inside UCSRC register.



One question is if you are going to be master or slave.
The UMSEL bit in USART
Control and Status Register C (UCSRC) selects between asynchronous and synchronous oper-
ation. Double Speed (Asynchronous mode only) is controlled by the U2X found in the UCSRA
Register. When using Synchronous mode (UMSEL = 1), the Data Direction Register for the XCK
pin (DDR_XCK) controls whether the clock source is internal (Master mode) or external (Slave
mode). The XCK pin is only active when using Synchronous mode.

https://extremeelectronics.co.in/avr-tutorials/using-the-usart-of-avr-microcontrollers/
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=18526&start=0

As I said I haven't used synchronous mode, you could do some reading by yourself about AVR's USART.
It seems that if you are master, there's nothing more you should do except setting the UMSEL bit.


Hope this helps,
Alexandros
 

OK I assume that you are using a function to send serial data, let's call it send_char(), because I don't know the actual name you are using.
Now the function that sends the four bits should look like this:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void send_4_bit (unsigned char dec_ascii)
{
  unsigned char dec = (dec_ascii & ~'0');
 
  if (dec & 8)
    send_char('1');
  else
    send_char('0');
 
  if (dec & 4)
    send_char('1');
  else
    send_char('0');
 
  if (dec & 2)
    send_char('1');
  else
    send_char('0');
 
  if (dec & 1)
    send_char('1');
  else
    send_char('0');
}



If you want to send DE801234 like your example, then the code would be:


Code C - [expand]
1
2
3
4
5
6
7
8
send_char('D');
send_char('E');
send_char('8');
send_char('0');
send_4_bit('1');
send_4_bit('2');
send_4_bit('3');
send_4_bit('4');



Please use this code and post back the results.



I haven't used synchronous mode, but according to the datasheet you need to set UMSEL bit inside UCSRC register.



One question is if you are going to be master or slave.


https://extremeelectronics.co.in/avr-tutorials/using-the-usart-of-avr-microcontrollers/
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=18526&start=0

As I said I haven't used synchronous mode, you could do some reading by yourself about AVR's USART.
It seems that if you are master, there's nothing more you should do except setting the UMSEL bit.


Hope this helps,
Alexandros


Sir i need to show the data for raising edge of the clock and i need the code for general suppose if i send DE807654 OR DE809999 what to do??.And whatever i send the data it will be stored in UDR register.I need to access the data from that register.
I am using the code as follows

char x[200];
int i;

for(i=0;i<8;i++)
{
while((UCSRA&(1<<RXC))==0);/*wait a byte has been recieved*/
x=UDR;
}
 

i need the code for general suppose if i send DE807654 OR DE809999
You must put more effort on this, the solution is given but you have to adjust it to your program. The scenario is that you have a 4-digit number and you want to split it into its digits and then send it to 4-bit format. The 4-bit code has been given and believe me, it is for general use. Now split a number into its digits? Please tale a look at the below edabord thread, it's all in there:
https://www.edaboard.com/threads/232284/#post990768


i need to show the data for raising edge of the clock
It seems that you don't even take a quick look to the datasheet. Whatever help you will get from a forum, cannot replace your own effort. As already told earlier, it is all in the USART chapter of the datasheet.

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top