|
|
View previous topic :: View next topic |
Author |
Message |
Cogitum
Joined: 22 Mar 2012 Posts: 70 Location: France (Paris)
|
PIC24FJ and RS232 |
Posted: Mon Apr 09, 2012 2:24 am |
|
|
HI,
I'm looking for the small example using CCS and PROTEUS to write
Just HELLO this one do not run :
Code: |
#use rs232(baud=9600,parity=N,xmit=PIN_F3,rcv=PIN_F2,bits=8)
//
// #use rs232(UART1,baud=0,parity=N,bits=8)
void main()
{
setup_spi( FALSE );
setup_spi2( FALSE );
set_uart_speed(9600);
setup_timer1(TMR_DISABLED);
WHILE (TRUE)
{
printf("HELLO\n\r");
delay_ms(300);
output_high(PIn_F4);
delay_ms(100);
output_low(PIn_F4);
delay_ms(100);
}
|
Why ?
I Tried different speed of clock and baud rate
File "h":
Code: |
#include <24FJ128GA006.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
//#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#use delay(clock=20000000)
#use fixed_IO(E_outputs = PIN_E0,PIN_E0,PIN_E1,PIN_E1,PIN_E2,PIN_E2)
#FUSES PR
|
Thanks in advance |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Apr 09, 2012 7:06 am |
|
|
rule #1. Proteus is NOT 100% reliable!!! Not worth the time it takes to download it.Unless it came with working, example code for your _specific_ PIC , NEVER,EVER assume it actually works.
rule #2. read the PIC datasheet,header file,examples here and there and decide which 'fuses' are correct for your PIC type and application.
rule #3. do NOT use 'fixed_io' until you've used real hardware and really need it. Instead let the compiler handle it.
rule #4. post your complete program, not just fragments, for us to make further comments. |
|
|
Cogitum
Joined: 22 Mar 2012 Posts: 70 Location: France (Paris)
|
PIC24FJ and RS232 |
Posted: Mon Apr 09, 2012 8:52 am |
|
|
Hi
Thanks a lot for your quick answer.
1) My program was complete (no partial)
2) This type of program RUN perfectly with the 18F672 and so on.
3) I'm not familiar with the new generation like PIC24FJ128GA006.
4) Looking a small example to print "HELLO".
Code: |
#include <main.h>
#use rs232(baud=9600,parity=N,xmit=PIN_F3,rcv=PIN_F2,bits=8)
// #use rs232(UART1,baud=0,parity=N,bits=8)
void main()
{
set_uart_speed(9600);
setup_timer1(TMR_DISABLED);
WHILE (TRUE)
{
printf("HELLO\n\r");
delay_ms(500);
}
}
|
====h code====
Code: |
#include <24FJ128GA006.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
//#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#use delay(clock=20000000)
//#use fixed_IO(E_outputs = PIN_E0,PIN_E0,PIN_E1,PIN_E1,PIN_E2,PIN_E2)
#FUSES PR //
|
Note : TX send some Characters but no the goods one in HEX :
00 30 CE C0 0E 30 C0 30 FE 30 30 00 CE 00 00 30
CE C0 0E 30 C0 30 FE 30 30 00 CE 00 00 30 CE C0
0E 30 C0 30 FE 30 30 00 CE 00 00 30 CE C0 0E 30
C0 30 FE 30 30 00 CE 00 00 30 CE C0 0E 30 C0 30
FE 30 30 00 CE 00
What's wrong ?
Best Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Apr 09, 2012 10:10 am |
|
|
1) you should post the compiler's version.....
2) you can get rid of the set_uart_speed as you've already done thesame with the use rs232(...)
3) you do have a max232 or equal between PIC and PC ?
4) looks like bad rs232 setup...baud rate,bits,??
data looks like it repeats every 14 characters....kinda 'interesting' as you're sending 7 characters....
I don't use the 24 series......just general observations |
|
|
Cogitum
Joined: 22 Mar 2012 Posts: 70 Location: France (Paris)
|
PIC 24 and RS232 |
Posted: Mon Apr 09, 2012 11:50 am |
|
|
Thanks Temtronic
Compiler is the last one : 4.132 !
I'm agree with you It seem the Baud rate problem ....
or Clock ?
PIC24 software is a little bit different of the 18Fxxxx
I have to make different trials to found the solution
Thanks again for you help
JacK |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Mon Apr 09, 2012 12:05 pm |
|
|
OK.
Your probem is probably the fuses.
You have the primary oscillator selected, but no fuse saying what type of oscillator to use for this.
I'd be suggesting (assuming you have a 20MHz crystal), something like:
#FUSES NOWDT,NOJTAG,NODEBUG,NOIESO,PR,NOCKSFSM,HS
Ignore the RS232. Start by just flashing an LED, with (say) a one second on/off, and check you get the right speed for this. Only move on to RS232, once the flash rate is right.
I think what is happening, is because you haven't got an oscillator selected it is failing to run the crystal, and falling back to the internal oscillator.
Best Wishes |
|
|
Cogitum
Joined: 22 Mar 2012 Posts: 70 Location: France (Paris)
|
PIC24 and RS232 |
Posted: Mon Apr 09, 2012 12:37 pm |
|
|
HI Ttelmah
Thanks a lot !
That was the Fuse problem
Best regards
Jacqk |
|
|
|
|
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
|