|
|
View previous topic :: View next topic |
Author |
Message |
Userr Guest
|
RS232 sending /0D q. |
Posted: Fri Dec 10, 2004 11:30 am |
|
|
My program work fine from terminal with CR
but in my program on C by Windows I can't recieve (CR or 0x0d 'end of line')
Maybe someone have example of program by win. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Dec 10, 2004 12:38 pm |
|
|
Google it, there are tons of examples for serial communication out there. |
|
|
Userr Guest
|
|
Posted: Sat Dec 11, 2004 12:17 pm |
|
|
Ok ton's but were is example with sending CR
I khow that is - \n, but it doesn't work. |
|
|
droll Guest
|
|
Posted: Sat Dec 11, 2004 12:58 pm |
|
|
I've created many apps using serial and the 0xod is always available.
post your code. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Sat Dec 11, 2004 3:10 pm |
|
|
Userr wrote: | Ok ton's but were is example with sending CR
I khow that is - \n, but it doesn't work. |
The '\n' in most MSDOS and Windows programs translates into 2 characters (0x0D and 0x0A) Try sending "\r\n" for a carriage return and new line. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Dec 11, 2004 5:39 pm |
|
|
\n - 0x0D and 0x0A
\r - 0x0D
\v 0 0x0A |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 11, 2004 6:51 pm |
|
|
Quote: | \n - 0x0D and 0x0A
\r - 0x0D
\v 0 0x0A |
But he's concerned about what his Windows program, written in MSVC,
is receiving from the PIC.
The CCS compiler translates those escape codes as:
\n = 0x0A -- linefeed
\r = 0x0D -- carriage return
\v = 0x0B -- vertical tab
rwyoung nailed it -- The original poster didn't know that
CCS only puts out 0x0A when \n is used with printf,
and that he must use "\n\r" to get both 0x0A and 0x0D. |
|
|
Userr Guest
|
|
Posted: Sun Dec 12, 2004 7:27 am |
|
|
Ok all work but,
That is Builder C++ function
Code: |
....
BuildCommDCB("9600,N,8,1", &dcbCommPort);
....
c++;
AnsiString a = IntToStr(c);
char *dat = a.c_str();
TransmitCommChar(hComm, dat[0]);
TransmitCommChar(hComm, dat[1]);
TransmitCommChar(hComm, dat[2]);
TransmitCommChar(hComm, dat[3]);
TransmitCommChar(hComm, dat[4]);
TransmitCommChar(hComm, dat[5]);
TransmitCommChar(hComm, dat[6]);
TransmitCommChar(hComm, dat[7]);
TransmitCommChar(hComm, dat[8]);
TransmitCommChar(hComm, 0x0d);
......
|
and that is PIC function
Code: |
#include <18F4320.h>
#device adc=8
#use delay(clock=40000000)
#fuses WDT,WDT128,H4, NOFCMEN, NOBROWNOUT, BORV20, PUT, NOCPD, NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOIESO, NOEBTR, NOEBTRB, NOMCLR, NOPROTECT, NOCPB, NOWRTB, NOWRTC, NOPBADEN
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
.....
#int_rda
void serial_isr() {
gets(text);
//printf(text);
x=atoi32(text);
}
|
In this sample if I don't use WDT my program
sometimes work fine , but sometimes hang up when I send this
text to PIC .
also, I use fast_io for all port - maybe that?
Trying to use 10Mhz without 4x-PLL - the same. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Dec 12, 2004 8:06 am |
|
|
You shouldn't use gets() inside of an isr.
I would never use gets(), too great a chance for your program to hang.
Use an isr and just receive the data and put it into a buffer. There are many examples on the board and CCS has an example file.
If you are sending strings from another micro or computer, I would use a NULL to terminate the string and look for that. |
|
|
Userr Guest
|
|
Posted: Sun Dec 12, 2004 10:03 am |
|
|
Thanks ,Mark.
I will will try to use it. (I found sample in CCS dir with receive the data and put it into a buffer )
In my program with Builder C++ I insert delay 1ms after each byte
transfer. And all work fine. But I know that is not good method. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Dec 12, 2004 10:26 am |
|
|
You shouldn't need to insert any delay. If you keep the interrupt handler short, the PIC shouldn't have any problems keeping up receiving the characters. Now the PIC of course has to process the message, so depending on what you are trying to do you obviously can't constantly stream messages at it without the PIC having time to process them. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Sun Dec 12, 2004 11:59 am |
|
|
Mark wrote: | You shouldn't need to insert any delay. If you keep the interrupt handler short, the PIC shouldn't have any problems keeping up receiving the characters. Now the PIC of course has to process the message, so depending on what you are trying to do you obviously can't constantly stream messages at it without the PIC having time to process them. |
Mark is right. Using the hardware UART and receive/transmit interrupts you can build a nice software FIFO. Works very well.
Go look at the examples EX_SISR and EX_SOISR (I may have spelled those wrong so just find the closest filename is the examples directory ).
If you feel up to the challange, you can apply a little queueing theory to size your receive and transmit buffers. Or just make them as large as your program can afford... _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Userr Guest
|
|
Posted: Mon Dec 13, 2004 1:29 pm |
|
|
Please correct me.
Code: |
#int_rda
void serial_isr()
{
next_in++;
buffer[next_in]=getc();
if(buffer[next_in]==0x0d) {x=atoi32(*buffer) ; next_in=0;}
if(next_in>10) next_in=0;
}
|
were timer0 use x variable int32 to show on screen
why x always 0(zero) |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Dec 13, 2004 2:07 pm |
|
|
This line
always increments the index first.
When you set
it always increments first so no value is ever stored in buffer[0]
*buffer is the same as buffer[0]. Since you never put anything in buffer[0] it is probably 0 so that is why
|
|
|
Userr Guest
|
|
Posted: Mon Dec 13, 2004 2:24 pm |
|
|
John P use this code
Code: |
int_rda
void serial_isr()
{
buffer[push++] = rcreg; // Store it
bit_clear(push, 5);
}
main()
{
pop=0;
push=0;
while(1)
{
if (pop != push) // Here's the check for new data
{ // Got something
new_data = incoming[pop++];
// Insert code to do whatever we do with new data
bit_clear(pop, 5); // As before, count to 31 then wrap
}
}
}
|
By this code I recieve at new_data any keyboad scan codes,
But how new_data make int32 and put in it incoming data [0..10] bytes?
Thanks, Mark, for all. |
|
|
|
|
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
|