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 CCS Technical Support

RS232-dspic30f4013
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
anhphong208



Joined: 23 Jun 2014
Posts: 29
Location: viet nam

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number

PostPosted: Thu Jul 03, 2014 7:44 am     Reply with quote

ezflyr wrote:
Hi,

First, learn to use the 'Code' buttons when posting your code. This will preserve the formatting, and make the code much easier to read.

The next thing I would do is to figure out a 'protocol' for the commands/data that you will send from your PC (application) to the PIC. You can make you life easy or hard with the design of the protocol. To make things easy, start every transmission with a unique character, and end every transmission with a carriage return <CR>. For example, you could define something like this:
Quote:

#M1:D90<CR>

This would set motor #1 to a 90% duty cycle. Hopefully, you get the point!

Here is an interrupt handler that you could use to receive the commands:

Code:

//-----< RS232 Packet definitions >-----
int1 RX_Command_Ready;      // TRUE If a receive packet is ready

#define RX_SIZE 10            // RS232 buffer for serial reception
char RxBuffer[RX_SIZE];       // RS232 serial RX buffer
int8 Index = 0;              // RS232 RX data IN index

#INT_RDA   // Interrupt driven RS232 routine
void rs232_isr(void)
{
   char temp;   // local data storage
   
   temp = fgetc(PC);   // get rx data

   // If we got a '#', then the command is beginning.
   if (temp == '#')
      {   
         Index = 0;
         RxBuffer[Index] = temp;
         Index++;
         return;
      }

   // If we got a CR, then the command is completed.
   if (temp == CR)
      {
         RxBuffer[Index] = temp;
         RX_Command_Ready = TRUE;
         return;
      }

   // Save the character to the receive buffer.
   RxBuffer[Index]=temp;

   // Check for buffer overflow.
   if ( Index >= (RX_SIZE - 1) )
      Index = 0;
   else
      Index++;
}


This is a 'linear' buffering arrangement that is probably well suited to your needs. Inside your Main() routine, you would have a check for Rx_Command_Ready, and when true, you would know a valid command has been received. Do something simple with this at first like toggling an LED via a command sent from your PC.

Get rid of all the TRIS stuff in your code. Without a Fast_IO directive it's not doing anything anyway. The compiler will handle the TRIS for you, so just delete it.

John

...........................thanks ezflyr
_________________
thanks
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

bug in serial uart
PostPosted: Thu Jul 17, 2014 3:19 pm     Reply with quote

I moved my project from 4.093 to 5.026 and receive stopped working on 30f4011 went back to 4.093 and it works again ccs is working on it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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