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

RS232-dspic30f4013
Goto page 1, 2  Next
 
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

RS232-dspic30f4013
PostPosted: Mon Jun 23, 2014 1:58 am     Reply with quote

help me communicate rs232 parts ... I used the dspic30f4013 ... I do not know the configuration declaration for dspic30f4013 ..... can share me some sample code for rs232 dspic elephant .... ...
I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jun 23, 2014 1:22 pm     Reply with quote

Hi,

What compiler are you using? Once we know that we will better be able to assist you!

John
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

RS232-dspic30f4013
PostPosted: Mon Jun 23, 2014 10:03 pm     Reply with quote

I am using ccs c 5015 ... I need help parts via RS232 UART and PWM ... dspic30f4013 .... I want to:
1. Communicate with dspic30f4013 PC (PC send 1 down sampling time (To) to dspic30f4013)
2. Dspic30f4013 received, implementation timer1 interrupt (# int_timer1) to interrupt the time is To...(# int_timer ...to use read ADC and send PC)....
3. Continuous PWM output from RD0 foot to Oven temperature control (with duty received from PC)
thanks ......
............I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jun 24, 2014 7:15 am     Reply with quote

Hi,

Whoa there, you've bitten off quite an ambitious project for a beginner! And, keep in mind that the forum is a 'help you' forum, not a 'do it for you' forum! You are going to have to do the 'heavy lifting' on this project, not us, but we'll be there to help....

Step #1 - Connect an LED up to an I/O pin on your PIC (with a suitable current limiting resistor), and flash it at a known rate, say 1 second On, and 1 second Off. Do this first, and you'll be well poised for Step #2 (connecting your PIC to the PC via a MAX232 IC).

Also, is this a real hardware project, or a simulation?

John
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

RS232-dspic30f4013
PostPosted: Tue Jun 24, 2014 7:53 am     Reply with quote

I'm sorry .... I just want you to understand my problem ... from which direction to guide me ... I will do circuit and will do step by your step instructions ...
....thanks
.......................I'm sorry .. I do not use much English so could mistake ... please ignore me............
_________________
thanks
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

Re: RS232-dspic30f4013
PostPosted: Thu Jun 26, 2014 8:12 am     Reply with quote

I had done the circuit ... and step 1 ... when I loaded code dspic down .. it was an error ... "verification of configuration failed" ..... here .... I used PICkit2 lED is turned on RD0 code.....
.................................................................................
#include <30F4013.h>
#device *=16 ADC=12
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NODEBUG
#use delay(clock=20000000)
#use rs232 (baud=9600, parity=N, xmit=pin_F3, rcv=pin_F2, bits = 8)

void main()
{

set_tris_d(0x00);
while(true)
{
output_high(pin_D0);
delay_ms(300);
output_low(pin_D0);
delay_ms(300);
}
}
..........................................................................
check your line Fuse (# fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, ​​NODEBUG) I declare properly? ... and explains why for me when I loaded it PICkit2 error .... "verification of configuration failed "......
.........................................................................................thanks
............I'm sorry .. I do not use much English so could mistake ... please ignore me
[/img]
_________________
thanks
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

Re: RS232-dspic30f4013
PostPosted: Thu Jun 26, 2014 8:18 am     Reply with quote

Can you guide me step #2?......thanks
..........................................
............I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Jun 26, 2014 9:38 am     Reply with quote

Hi,

Well, you didn't say clearly if your LED is blinking or not?? Is it??

Moreover, you ignored my suggestion to use 1 second On/Off times to blink your LED. Rather, you selected a rather arbitrary On/Off times of 300ms to blink your LED. That's going to be a lot harder to time, so it effectively defeats the whole purpose of my suggestion which was to (1) verify that your PIC is actually running, and (2) verify that it's running at the correct speed.

You aren't ready for step #2.

John
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

RS232-dspic30f4013
PostPosted: Thu Jun 26, 2014 10:11 am     Reply with quote

I checked with LED on / off 1s .....
LED light off solution 1s ...
Here is the code

Code:

#include <30F4013.h>
#device *=16 ADC=12
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NODEBUG
#use delay(clock=20000000)
#use rs232 (baud=9600, parity=N, xmit=pin_F3, rcv=pin_F2, bits = 8)

void main()
{
   
   set_tris_d(0x00);
   set_tris_b(0x00);
   output_d(0x00);
   while(true)
   {
     output_high(pin_D0);
     delay_ms(1000);
     output_low(pin_D0);
     delay_ms(1000);
   }
}

LED is blinking
thanks
I'm sorry. I do not use much English so could mistake ... please ignore me
_________________
thanks
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

RS232-dspic30f4013
PostPosted: Thu Jun 26, 2014 10:29 am     Reply with quote

I'm sorry I did not do step 1.....I did check step #1(1s)... dspic30f4013 works well and blinking leds .....
Can you guide me step #2?......thanks
............I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Jun 26, 2014 1:59 pm     Reply with quote

Hi,

Step #2 is to connect the UART of your PIC to a serial COM port on your PC. To do this you'll to use a MAX232 IC (or similar), as the voltage levels/polarities of the PIC are not directly compatible with the PC. Google is your friend here, and you'll find lots of help with what you'll need, and how to connect it all together.

Once the hardware is done, write a small program that uses the PIC UART to continuously send a single character from the PIC to the PC. Use a 'terminal program' (Hyperterminal, RealTerm, etc.) on the PC to receive this character. Once you can see the steady stream of characters being received on your PC you'll know that PIC -> PC communications are working. Next, write a small program that receives a character using the PIC UART, and then immediately 'echoes' it back. In this way, any character that you type on the PC terminal program will be sent to the PIC, and then sent right back to the PC. Once that works, you will have verified PC -> PIC communications as well.

Get your hardware squared away first, and then let us know how you make out!

John
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: Fri Jun 27, 2014 7:34 am     Reply with quote

I checked Step #2 ... dspic30f4013 good run down .... I sended the character "k" to dspic30f4013 and pack up PC by dspic character "k" .... here is the code
.................................................................................
#include <30F4013.h>
#device *=16 ADC=12
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NODEBUG
#use delay(clock=20000000)
#use rs232 (baud=9600, parity=N, xmit=pin_F3, rcv=pin_F2, bits = 8)

char data;
#INT_RDA
void truyen()
{
data=getc();
if(data=='k')
{
printf("k");
}
}
void main()
{

set_tris_d(0x00);
set_tris_b(0x00);
output_d(0x00);
ENABLE_INTERRUPTS(INT_RDA);
ENABLE_INTERRUPTS(GLOBAL);
while(true)
{

}
}
..................................................................................................
I used 2 feet of dspic 25 and 26 for data transfer .....
..............................................................
Can you guide me step #3?......thanks
............I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Jun 27, 2014 9:32 am     Reply with quote

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
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

RS232-dspic30f4013
PostPosted: Fri Jun 27, 2014 10:52 am     Reply with quote

thank you very much ...... I checked dspic30f4013 by communicating with c # (turn off LED) ... and was successful ......
Can you guide me one sample code of PWM dspic30f4013 ?
..........................
............I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
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

RS232-dspic30f4013
PostPosted: Fri Jun 27, 2014 11:16 am     Reply with quote

I still do not know how to set up for dspic 30f4013 PWM mode ......
dspic30f4013-it has 4 PWM channels and I selection RD0...I do not know how to turn on PWM and pulse duty setting for channel RDO...
Can you give me a sample code for this problem?
thanks
I'm sorry .. I do not use much English so could mistake ... please ignore me
_________________
thanks
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 1, 2  Next
Page 1 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