CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Help to 2 serials

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rosiley



Joined: 29 May 2014
Posts: 18
Location: Brasil

View user's profile Send private message

Help to 2 serials
PostPosted: Mon May 08, 2017 6:30 am     Reply with quote

Hello everyone.

I have two doubts here.

1: I have a hardware that consists of an adc converter. This converter sends via rs232 the value converted in volts and the same is shown in the software made in C#. The value shown for example is 1234. Only in soft this value is not stable. Already checked in Hyperterminal and everything ok.

Code:
string An_Input, str = null;       
        long tempox = 0;

        public void RecepcaoSerial()
        {
            An_Input += serialPort1.ReadExisting();

            lblSensor.Text = An_Input + " mV\r\n";

            txtSensor.AppendText(DateTime.Now + " - " + An_Input + "\r\n");

            str += An_Input;
            An_Input = null;

            if (chart1.Series[0].Points.Count > 8)
            {
                chart1.Series[0].Points.RemoveAt(0);

                chart1.Update();
            }

            chart1.Series[0].Points.AddXY(tempox, int.Parse(str.Substring(0, 4)));

            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss\n"; // I use \n (cr).

            tempox++;
            str = null;

        }

2: How do I get this same value to be transmitted to another serial port, I know we can do it for soft but I have no concept, it follows what I think can work.
Code:

#include <18f4553.h>
#include <stdlib.h>
#include <CTYPE.h>
#include <STRING.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#use rs232(stream=RS232HW,baud=9600,xmit=PIN_C6,rcv=PIN_C7)//Hw UART-->INT RDA
#use rs232(stream=RS232SW,baud=9600,xmit=PIN_B1,rcv=PIN_B0,FORCE_SW)//SW UART-->INT EXT
.
.
.
.
.
.
#INT_RDA //Port interruption treatment would be serial port HW
void hw_uart_isr (){
.
.
.
.
.

}

#INT_EXT //Port interruption treatment would be SW
void sw_uart_isr (){
.
.
.
.
.
.
}

void main ()
{
ext_int_edge(H_TO_L);

enable_interrupts(INT_EXT);
enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);

fprintf(RS232HW,"send to serial port HW\n\r");

fprintf(RS232SW,"send to serial port SW\n\r");




}
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Mon May 08, 2017 9:25 am     Reply with quote

Forget it....

Use a PIC with two hardware serials.

Trying to use a software serial is almost certain to result in corrupted data, or loss of characters.
temtronic



Joined: 01 Jul 2010
Posts: 9105
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 08, 2017 10:00 am     Reply with quote

mr T is 100% correct.
Use an 18F46K22 (40 pin) or 18F26K22 (28 pin). They both have TWO hardware UARTS.
The 46K22 is my 'goto' PIC or 'Swiss Army Knife' PIC. LOTS of memory, peripherals AND works at 3 or 5 volts at FULL speed !

The CCS supplied ex_sisr.c test program does work for BOTH serial ports at 115K2 baud and I've never missed a single byte in years of 24/7 use.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group