RS232 noob needs more info

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

Hi guys I am using AVR644p now, taking data from ADS1252(TI). I managed to get nice waveforms on oscilloscope, and now I would like to display it on the screen (Excel? Hyperterminal?)

I am a noob to RS232 so any advice is very much welcomed :)

I have connected my R1IN(pin13) and T1OUT(pin14) of ICL232 chip to RD(PIN2) and TD(PIN3) of RS232 cable, together with some 1uF polarised decoupling capacitors for the chip. On the other side, T1IN(pin11) and R1OUT(pin12) of the chip are connected to the TXD1 and RXD1 pins on AVR.

QUESTION ONE: how do I read out the data using RS232?

I am using another USART as USART_SPI mode to read data from my ADC. The code is as follow:

            //Write to data register to initiate data transfer
            UDR0= 0;
            //Wait till 8 bits is received
            //Do nothing  when Receive Complete Flag is ZERO (  means when it has not yet completely received data)

            while ((USART_CSR_A_Receive_Flag  & UCSR0A) == 0)
            {
            }
            //Read the data
            //UDR0 is the 8- bit USART Data Register
            Data[2] = UDR0;


            UDR0 = 0;
            while ((USART_CSR_A_Receive_Flag  & UCSR0A) == 0)
            {
            }
            Data[1] = UDR0;


            UDR0 = 0;
            while ((USART_CSR_A_Receive_Flag & UCSR0A) == 0)
            {
            }
            Data[0] = UDR0;

With this code I successfully see 3 consecutive bytes of data on oscilloscpoe.

A friend suggested that I need to take snapshot at every 8 sets of reading and stream that. The rough code he suggested is as follow:

unsigned char ToU[3]; //to usart

//after reading from ADC
Loop = (Loop + 1)&7;

If (Loop == 0); //counted to 8
{ 
ToU[0] = Data[0];
ToU[1] = Data[1];
ToU[2] = Data[2];
}
int streamLoc = 0; //initialise index

if streamLoc <3>; //take in 3 bytes of data
USART_DataReg = ToU[streamLoc ++]; //increment


QUESTION TWO: how to I put the data from USART data register of this USART(for ADC) to the other USART(for RS232)?

QUESTION THREE: data from RS232 is in binary right? how do I read it on the computer?

QUESTION FOUR: do I need to convert the binary data to hex data first? what do I use for conversion?

QUESTION FIVE: how do I display that on lets say Excel?

Many thanks :)

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

Firstly, read up on the use of the function 'printf'. This should answer most of your questions.

To get data into Excel, you would normally use CSV formatted strings. These look a little like this:

1234,4567,12,0........

So for four samples, you would:
printf("%d,%d,%d,%d\r\n",sample1,sample2,sample3,sample4);
On the PC side, you would use a terminal program to capture this data into a file then import this into Excel.

Note that you are not the first person wanting to do this - some searching will yield plenty of information.

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

Thanks. I just found tutorial written by Dean Camera and am reading it now. I will do the Excel bit last. Anyway thanks!