![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
czorgormez
Joined: 14 Jan 2021 Posts: 6
|
rs485.c problem with 16f628-16f1827 chips |
Posted: Fri Jan 15, 2021 1:11 pm |
|
|
hi everyone
I am using rs485.c driver code with 18f4520, 18f452... several 18F chips
without a problem. I needed to use same structure with 16f628 chip and it didn't work (ext_interrupts = FALSE configuration).
I investigated the problem with my scope and i find out the chip is not transmitting any data. The uart configuration is below:
Code: | #use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, force_sw, errors, stream=RS485_CD) |
(the MULTI_MASTER - RCV pin was always high at this test), the enable pin is going high and pulse length matches with bit time, but nothing coming out from TX pin.
So i investigated further, and i see the code is receiving bytes with RDA interrupt and sending bytes with software uart. Errors and multi master enabled. Then i stripped down the code to find what is wrong.
Code: |
#define RS485_USE_EXT_INT FALSE
#define RS485_RX_PIN PIN_B1
#define RS485_TX_PIN PIN_B2
#define RS485_ENABLE_PIN PIN_B3
#define RS485_RX_ENABLE PIN_B3
#use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, errors, stream=RS485)
#use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, force_sw, errors, stream=RS485_CD)
disable_interrupts(GLOBAL);
test_loop(){
setup_uart(FALSE);
rs485_collision = 0 ;
fputc((unsigned int16)0x100|0x10,RS485_CD);
fputc((unsigned int16)0x100|0x20,RS485_CD);
fputc(0x055,RS485_CD);
delay_ms(200);
} |
The code above is doing almost same with rs485.c and it is still not sending any data. But when i choose TX pin else than hardware uart pins it works
and sending data as expected. So same code works with 18F chips (HW uart TX pin can send software serial) but in 16F series it is not working properly. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 15, 2021 1:36 pm |
|
|
So your complaint is that you want it to use a software UAR on the
hardware UART pins, and it won't do it.
What's your compiler version ? |
|
![](templates/subSilver/images/spacer.gif) |
czorgormez
Joined: 14 Jan 2021 Posts: 6
|
|
Posted: Fri Jan 15, 2021 1:48 pm |
|
|
yes that works on 18F chips but not in 16F series (i tried 16f628a and 16f1827)
the reason i use sw uart on hw pins is to be compatible with rs485.c code.
the comp. version is 5.026 |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Fri Jan 15, 2021 3:36 pm |
|
|
Well I'm confused...
..getting easier the older I get !
1st how can you get interrupts to work with a SW UART ????? Didn't think that was possible( without extra pins and code...)
2nd how can a SW UART work when a HW UART doesn't on the same pins ???
SW UART is bigbanged by PIC(time consuming/dedicated) whereas HW UART is 'stand alone' and allows for interrupts. |
|
![](templates/subSilver/images/spacer.gif) |
czorgormez
Joined: 14 Jan 2021 Posts: 6
|
|
Posted: Fri Jan 15, 2021 4:21 pm |
|
|
@temtronic
can you check rs485.c driver please. that is how ccs wrote the driver. hw uart interrupt (RDA)on RX and not using HW uart on TX side. they do this way because hw uart is not supporting multi master.
1- well it is not working with interrupt at TX side but at RX side it uses external interrupt pin to jump getc (without HW uart configuration)
2- in ccs rs485.c driver code. when transmitting it disables interrupts and hw uart on that pins and send the data. after that it enables hw uart and waits for data. this is why there is 2 #use_rs232 statements on the code at the beginning.
and this configuration with rs485.c code works fine with 18f series chips. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 15, 2021 6:19 pm |
|
|
I installed CCS vs. 5.026 and ran the test program below in hardware.
It worked. It displayed "ABC" in the TeraTerm window.
I installed a 16F628 on a PicDem2-Plus board. I jumpered pin B2 on the
16F628 to the Max232 chip on the board, and connected the board to my
PC's serial port.
I changed the output characters in your fputc() statements to text that
would be easily readable on TeraTerm.
Code: |
#include <16F628.h>
#use delay(internal=4M)
#define RS485_USE_EXT_INT FALSE
#define RS485_RX_PIN PIN_B1
#define RS485_TX_PIN PIN_B2
#define RS485_ENABLE_PIN PIN_B3
#define RS485_RX_ENABLE PIN_B3
#use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, errors, stream=RS485)
#use rs232(baud=9600, xmit=RS485_TX_PIN, rcv=RS485_RX_PIN, enable=RS485_ENABLE_PIN, bits=9, long_data, force_sw, errors, stream=RS485_CD)
//======================
void main(void)
{
delay_ms(200);
disable_interrupts(GLOBAL);
setup_uart(FALSE);
TXEN = 0;
fputc((unsigned int16)'A', RS485_CD);
fputc((unsigned int16)'B', RS485_CD);
fputc('C', RS485_CD);
while(TRUE);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
czorgormez
Joined: 14 Jan 2021 Posts: 6
|
|
Posted: Fri Jan 15, 2021 7:21 pm |
|
|
Ok i found the mistake
i started this project and configure fuses and IO lines with wizard, and there was this 2 line on the main.h file
Code: | #use FIXED_IO( A_outputs=PIN_A2 )
#use FIXED_IO( B_outputs=PIN_B5,PIN_B4,PIN_B0 ) |
when i disable this lines it started transmitting. but i never thought that would be a problem. because these FIXED_IO directives are not setting uart related pins B1, B2, B3. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Sat Jan 16, 2021 2:50 am |
|
|
A 'fixed_io' directive, is actually a 'port wide' directive. So using fixed_io on
pins on port B, says that the whole of port_b is using fixed IO.
For your code, B2, & B3, need to be added to the pins set as 'outputs'.
#use FIXED_IO( B_outputs=PIN_B5,PIN_B4,PIN_B3, PIN_B2,PIN_B0 )
FIXED_IO, is not 'pin wide'.
The manual does say it applies to the 'port'. |
|
![](templates/subSilver/images/spacer.gif) |
czorgormez
Joined: 14 Jan 2021 Posts: 6
|
|
Posted: Sat Jan 16, 2021 10:19 am |
|
|
i assumed the wizard would do this correctly when i choose serial ports. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Sat Jan 16, 2021 11:08 am |
|
|
The 'wizard' is just one person's idea of how to program...so 'defaults' and setup parameters won't necessarily be what YOU need......
I've never ever used the 'wizard' in 2.5 decades of 'playing with PICs'.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Sat Jan 16, 2021 12:50 pm |
|
|
Also, the 'wizard', at heart assumes you are using standard IO.
Anything else it won't really cope with properly. |
|
![](templates/subSilver/images/spacer.gif) |
czorgormez
Joined: 14 Jan 2021 Posts: 6
|
|
Posted: Sun Jan 17, 2021 9:49 pm |
|
|
thanks pcm, ttelmah, temtronic. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|