View previous topic :: View next topic |
Author |
Message |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
serial comminication |
Posted: Fri Oct 06, 2023 5:01 am |
|
|
Hello
I am sending 5 bytes of data from PIC to PC. There is no problem. But I am sending 66bytes of data from my PC. I want to print that incoming data to the screen. It didn't work I send 66byte hex code from PC, for example ff 0d Code: |
#include <18F47Q83.h>
#use delay(crystal = 16MHz)
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(UART1, baud=9600, receive_buffer=256, parity=N, stop=1)
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
#define SEND_DATA_SIZE 5
#define RECEIVE_DATA_SIZE 66
void SendTask(void)
{
unsigned int8 i;
char sendDataHEX[SEND_DATA_SIZE] = {0x1B, 0xE7, 0x01, 0x03, 0x0D};
for(i=0;i<SEND_DATA_SIZE;i++)
{
putc(sendDataHEX[i]);
}
}
void main()
{
lcd_init();
int1 doSend = TRUE;
char receivedData[RECEIVE_DATA_SIZE];
while(TRUE)
{
if(doSend)
{
SendTask();
doSend = FALSE;
}
// PC'den gelen veriyi al
for (int8 i = 0; i < RECEIVE_DATA_SIZE; i++)
{
output_high(PIN_C5);
receivedData[i] = getc();
lcd_gotoxy(i,1);printf("%02X ", receivedData[i]);
output_low(PIN_C5);
}
doSend = TRUE;
}
} |
_________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19531
|
|
Posted: Fri Oct 06, 2023 5:23 am |
|
|
One key thing. You need enable_interrupts(GLOBAL); at the start of your
main, or the receive buffer will not be working.
Can your LCD show this much?. You are printing 3 characters for each one
received, so the display would need 198 columns!.... |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Fri Oct 06, 2023 5:34 am |
|
|
Yes I know. I fixed it. I press the PC screen. Or when I press the LCD, the character is printed in type T. 4x20 character LCD works fine. Now I corrected what you said. So why doesn't it run the SendTask() function after the er transaction? after for loop doSend = TRUE; I'm doing it. Code: |
#include <18F47Q83.h>
#use delay(crystal = 16MHz)
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(UART1, baud=9600, receive_buffer=256, parity=N, stop=1)
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c>
#define SEND_DATA_SIZE 5
#define RECEIVE_DATA_SIZE 66
void SendTask(void)
{
unsigned int8 i;
char sendDataHEX[SEND_DATA_SIZE] = {0x1B, 0xE7, 0x01, 0x03, 0x0D};
for(i=0;i<SEND_DATA_SIZE;i++)
{
putc(sendDataHEX[i]);
}
}
void main()
{
lcd_init();
int1 doSend = TRUE;
char receivedData[RECEIVE_DATA_SIZE];
enable_interrupts(GLOBAL);
while(TRUE)
{
if(doSend)
{
SendTask();
doSend = FALSE;
}
// PC'den gelen veriyi al
for (int8 i = 0; i < RECEIVE_DATA_SIZE; i++)
{
output_high(PIN_C5);
receivedData[i] = getc();
printf("%02X ", receivedData[i]);
output_low(PIN_C5);
}
doSend = TRUE;
}
} |
_________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Fri Oct 06, 2023 5:40 am |
|
|
And I also want to check if the RX is no longer receiving data, that is, if the data reception bus is empty. Is there such a flag? He did the retrieval. finished. I'll check it later., _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19531
|
|
Posted: Fri Oct 06, 2023 6:13 am |
|
|
kbhit tells you if there are any characters waiting to be read.
rcv_buffer_bytes() returns how many characters are in the receive buffer
at any time. Look in the manual for both. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Oct 06, 2023 7:07 am |
|
|
#use rs232 is also missing ERRORS _________________ Google and Forum Search are some of your best tools!!!! |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Fri Oct 06, 2023 8:06 am |
|
|
well I use gets and puts to receive and send strings. But I couldn't get it to work. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Fri Oct 06, 2023 9:40 am |
|
|
So, can I use 2 rs232() streams in the PIC? For example.
#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7
#use rs232(UART1, baud=9600, receive_buffer=256, parity=N, stop=1,bits=8,ERRORS)
I will use it. This way I will press the screen on the PIC. I will push the other one to siow.exe for control purposes. If I make it #use rs232(ICD, baud=9600), will it work? _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19531
|
|
Posted: Fri Oct 06, 2023 1:35 pm |
|
|
Yes, BUT.
You chip has multiple hardware UART's, so 'yes'.
BUT. There are hardware restrictions on which pins can be used.
You need to read the data sheet. In particular Table 21-1, and the rest
of that section about the PPS. This shows which pins each port can
be allocated to.
You show just one #use RS232. You need to setup a second, and use
stream names for each. Then use getc and putc _with these names_. |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Fri Oct 06, 2023 11:32 pm |
|
|
I will take into account what you said and try it.
I am very sorry. I examined the lcd.c library. But when I added this code #define LCD_DATA_PORT getenv("SFR:PORTD") I connected it to D4-D4,D5-D5,D6-D6,D7-D7. But I didn't understand where to connect the RS, RW, and E pins. Where is it written. By the way, if I write as follows, the LCD works and there is no problem. But it seems better to write one line instead of defining them one by one.
Code: |
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#include <lcd.c> |
_________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19531
|
|
Posted: Sat Oct 07, 2023 4:17 am |
|
|
I suggest you foget the lcd.c library!....
Instead goto the code library here and get PCM_programmers flex_lcd
driver. This is vastly more flexible, and works really well. Much more
capable than the CCS supplied driver. |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Oct 11, 2023 6:30 am |
|
|
Could there be a situation where the RX terminal times out? Data is coming to the PC. But when I try to read it with the processor, I cannot receive the data. RX seems like it can't receive data. It's like it's locked. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9234 Location: Greensville,Ontario
|
|
Posted: Wed Oct 11, 2023 6:39 am |
|
|
You really need to post your current code as there can be several reasons why it may not work.
I always code/compile/test a simple 'PC ECHO' program when needing 'serial communications. I use the CCS supplied ex_sisr.c code and type in a PC terminal program, which sends bytes to PIC, the PIC then returns them to the PC screen. This is a simple test to confirm the hardware is correct as well as basic PIC C code functions as it should. |
|
|
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Oct 11, 2023 6:44 am |
|
|
I am using the 3.3v ethernet kit. There is a stereo jack on the rs232 part. When sending data, for example, I send characters with putc. Shouldn't I see a signal at the TX end? Also, I should see a signal at the RC end when receiving data. Is it true? _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9234 Location: Greensville,Ontario
|
|
Posted: Wed Oct 11, 2023 7:38 am |
|
|
no......
'RS-232' historically had +-12 volt signals ,over the years it's been 'modified' several times and today's PC don't have 'RS-232' comm ports
I suspect your PC has some form of USB serial interface ?? Some 'module' ?? Post that...it could be USB<> TTL or USB<>RS232 they are not the same....
That 'mini phone jack' isn't 'RS-232' by definition either........
then there's the '3.3v ethernet kit'... sigh... ethernet isn't 'RS-232' so now you're really confusing an old guy like me !!
You should post that product info as well,or a link to it.... |
|
|
|