rs-485

Coding and general discussion relating to user created compiler modules

Moderators: David Barker, Jerry Messina

Post Reply
richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

rs-485

Post by richardb » Mon Dec 11, 2023 9:06 am

Hi I don't know if anyone has a simple fix for this but I have just started using rs-485 and don't have much experience with it. I wanted to add this to an existing project, and i was just planning on setting the DE/_RE signal manually just before sending and setting low after sending but it seems to clip of the last chars which i assume is once the char is copied to the buffer the program can resume and sets the pin low before all the data is sent.

I can fix this by inserting a 300us delay before setting the pin low, but it doesnt seem ideal. I have had a look through the data sheets but just couldn't find anything except the "TRMT" bit in a status register.

Is there a pin to do this directly or some other interrupt method?



thanks in advance

Richard
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: rs-485

Post by Jerry Messina » Mon Dec 11, 2023 3:13 pm

Unfortunately, on most PIC18 devices the TRMT status bit must be polled... there's no interrupt associated with it.
Some of the newer devices have hardware flow control (Q40/41, Q43, etc) that can do the job.

If you don't have one of these then you have to do it manually... either wait some amount of time or use a timer ISR to do it.
The amount of time is baudrate dependent, and you'd have to wait up to 2 char times to ensure the TSR is empty.

If you have an RS485 transceiver that can do full-duplex (or at least has separate TX and RX enables), one trick I've used is to permanently enable the RX. This allows you to "see what you transmit", so while you're transmitting you can just read the data you're sending and throw it away.
When you receive the last byte you know you can disable the TX. This also allows a sort of "poor man's" collision detection.

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: rs-485

Post by Jerry Messina » Mon Dec 11, 2023 3:39 pm

I forgot to mention... if you're polling TRMT you may need an additional delay before disabling the TX.
TRMT gets set half way through the STOP bit, so if you don't have external failsafe biasing resistors the STOP bit will get cutoff too soon.
You need an additional 1/2 bit of delay time.

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Re: rs-485

Post by richardb » Tue Dec 12, 2023 6:39 pm

Thanks Jerry

Good call on the Q series parts.

I think i'll put up with the delay for now but i will look to see if i can swap in a q series part at some stage.

Rich
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: rs-485

Post by Jerry Messina » Tue Dec 12, 2023 11:10 pm

If you do switch, check out the 18F27Q43... it has a little bit of everything, along with 5 UARTS and 8K of RAM.
The only downside is the I2C peripheral. Since it doesn't have an MSSP you'd have to use one of the software I2C modules with it.

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Re: rs-485

Post by richardb » Wed Dec 13, 2023 1:02 pm

i will look t that part as i have a board that has an 18f26k22 and possibly looks pin compatible.

unfortunately the main board that i wanted to add rs485 has an older 18f6723 which is 64 pins and i cant seem to find any q parts with that many pins.


i have to say i find the microchip website just so awful for finding chips these days.

Rich
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: rs-485

Post by Jerry Messina » Wed Dec 13, 2023 2:51 pm

The 28-pin parts are pin compatible, so you should have no hdw issues replacing a K22 with a Q43.

For whatever reason they haven't released any new parts with >= 64 pins in a while... I think the last one was the 18F6xK40, and that was before they added the hardware flow control feature.

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Re: rs-485

Post by richardb » Tue Dec 19, 2023 7:20 am

Great I might try this next year :)

PS any suggestions for a bootloader for either of these parts for internal osc at 64MHz? for rs232...



Thanks again Jerry



Rich
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: rs-485

Post by Jerry Messina » Tue Dec 19, 2023 2:25 pm

There's the MicrocodeLoader (MCLoader) that comes with SF. If you use UMC mode you can create and build files for any configuration.
It's a simple serial bootloader that resides in high-memory. Checkout https://www.sfcompiler.co.uk/wiki/pmwik ... .UMCLoader
You can access the help file from the IDE 'View | Loader... | Help'. Although the info there is a bit dated, the basic process is the same. Also check the MCLoader folder.

If it sounds like something you'd be interested in I can help if need be. I have an asm file for the K22 hanging around, but I'd need to check and see if it needs updating since it relies on some external mpasm setup (I haven't used these in a while, so it's all a little rusty).

I have one for a K42 too, which could probably be ported to a Q43 without too much bother.

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Re: rs-485

Post by richardb » Thu Dec 21, 2023 7:18 am

Thanks Jerry,

I'll look at getting some q43 parts and get them working in the current project.

I'm feeling bad about not starting this as a new thread.

is there a specific website dedicater to umc?

do i need to add anything to the swordfsh code to "use"/skip over the bootloader?

Thanks again

Rich
Hmmm..

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: rs-485

Post by Jerry Messina » Thu Dec 21, 2023 1:36 pm

You can always start a different thread about using the UMC if you like.
There's no different forum, just the wiki page and the info found in the swordfish MCLoader\UMC folder.

With UMC, you build your app code as you would normally. When you program the UMC code into the uC,
the RESET vector will point to the UMC code, so that will run at startup. It will try to connect via UART
to the UMC app on the PC, and if it doesn't get a response it'll run the app code (assuming there is any).

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: rs-485

Post by David Barker » Wed Dec 27, 2023 10:42 am

I think Jerry has covered it, but this is what I put on my website some time ago:

http://www.mecanique-web.co.uk/downloads/umc/

the protocol PDF may be of interest

richardb
Posts: 310
Joined: Tue Oct 03, 2006 8:54 pm

Re: rs-485

Post by richardb » Wed Dec 27, 2023 4:47 pm

Thanks David

I'll have a try at this when i have a board to try it on and some time.

Rich
Hmmm..

Post Reply