RS232 Program conflict

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

RS232 Program conflict

Post by Ondra »

Good day all. I have a program where I am using timer 1 to maintain a time clock and flash an Led as a status indicator. I also have in main a loop containing an RS232 component receiving data and updating a variable which is then bit banged out at 2400bps. What I noticed is that the RS232 works find until the led starts flashing and the led works find until the RS232 starts receiving. What I would like to do is, rather then put the RS232 receiving in a loop in main is there a way to set it up so that it runs inside a macro which is called only when data is available at that port. I think the RS232 procedure is slowing down the program. Any suggestions?

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Program conflict

Post by Benj »

Hello Ondra

It is possible to configure the UART so that an interrupt occurs whenever a byte is received. This interrupt would then read the byte and perform any required processing.

If you look up on the forums regarding custom interrupts and the PICmicro datasheet then you should be able to get this working. Remember to keep it simple so you can be sure which parts are working and which parts still need work.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Thanks Ben. I took your advice and done some reading through the forum and the data sheet for the F1690 and on page 133 of the data sheet it say that the enable register address is 18h is that what goes in the custom interrupts Enable register? It also say that the enable bit is Bit 7 am I correct with this? For the flag register it looks like the address is 0ch and the Enable bit is 5 am I correct. And do I put the actual values I have stated here or do I convert the values to Hex. Also I have no Idea of what would be the Initial enable code. I would appreciate some help with that?

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Ok scratch that I was looking in the wrong section of the data sheet. I found bit 5 of register address 8ch RCIE in PIE1 is the correct address and enable bit and that bit 5 of Address 0ch RCIF is the correct flag bit. I tryed to put these values in as is with no additional enable code and here what happened when I tryed to compile it. When I take out the interrupt it compiles correctly with the interrupt I get this error. O and again do I put the the characters in as I have above or do I convert to hex, and if I have to convert, is it 0 and 8 that I am converting or do I convert 0ch and 8ch? As well do I convert the bit numbers to Hex?

Ondra

C:\E-Tank\flowcode\ElinK\TimeCaptureRS232Out_B.c(610): error: missing semicolon
C:\E-Tank\flowcode\ElinK\TimeCaptureRS232Out_B.c(624): error: missing right paren
C:\E-Tank\flowcode\ElinK\TimeCaptureRS232Out_B.c(624): error: missing semicolon
C:\E-Tank\flowcode\ElinK\TimeCaptureRS232Out_B.c(616): error: failure

failure

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: RS232 Program conflict

Post by Steve »

Please post the C code file (or at least the lines 600-630) onto the forum and it will help us work out what is wrong.

Unfortunately, it's a little late here now for a reply, but I'll try to answer this again later tonight from home.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Here's the file.
Thanks

Ondra
Attachments
TimeCaptureRS232Out_B.c
(10.51 KiB) Downloaded 423 times

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: RS232 Program conflict

Post by Steve »

Sorry for the late reply - it's been a busy weekend!

Your error is in the C file on the final line of this lot:

Code: Select all

	//Interrupt
	//Interrupt: Enable SerialIn
	intcon.GIE=1;
	8ch.5=1;
Instead of "8ch", try the name of the register itself - i.e. "pie1".

Also, you could use "RCIE" instead of "5".

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Thanks Steve.
Shoulds I do the same with the flag register? That is use the Register name "pir1" and bit name "RCIF"? Also is there any additional code that I should include? The data sheet for the flag Reg says that the flag bit RCIF is cleared by reading RCREG. Is this just stating the obvious. Or do I need to handle this with additional code?

Ondra

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: RS232 Program conflict

Post by Steve »

Yes - use "pir1" and "RCIF".

I'm not sure if you need additional code. I know that Ben has done this before and I'll ask him to put some code up onto the web this morning.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

I'll be looking out for it. Thanks again.

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Program conflict

Post by Benj »

Hello

There is now an example of the incoming RS232 interrupt available from our examples page.

http://www.matrixmultimedia.com/Flowcode_Examples.php

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Hi Ben. I'm trying to understand the program flow. I noticed that you placed an Interrupt disable at the bottom of Main. Since the Interrupt only occurs when data is present at the RX pin why would you want to disable it?
I thought that in Main, outside of interrupts and Items placed inside of loops that all processes run once at the startup of the program. Looking at this it looks like the interrupt would be enabled and then disabled during startup. Could you clarify my thinking on this.
Also for the RS232_Rx interrupt, outside of the Enable Register and bit, and Flag Register and bit, is there any "Additional Enable Code" needed for the interrupt to work? I'm using a PIC 16F690.


Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Program conflict

Post by Benj »

Hello Ondra

I have updated the RS232 interrupt example now as there were a couple of problems with it before mainly due to the fact that I was editing the file with my beta version of Flowcode.

The disable icon is only there as an example. It does not actually get called by the example program as it is outside of the main loop.

The interrupt is simple enabled and then the infinite loop is started.

There is an additional enable code of intcon.PEIE = 1; this allows the peripheral interrupts to trigger the main interrupt.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Thanks for your help today Benj.

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Ok guys this is not working. The program is not interrupting. I have it calling a macro that sends a 1 out to turn on an LED and nothing happens.
I know that you where having some issues with the 16F690 FCD file. Could it be that this in causing issues with what I'm trying to do?
Also Ben, I noticed that you put "pie1" as your flag register in the example flowcode file on you examples site. Steve told me earlier in the topic that
I should use "pir1" as my flay register. I tried them both nothing works. This looks like this should be simple. Please have a look for me. Also "intcon.PEIE=1" is that the right additional code for the 16F690?


Ondra

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: RS232 Program conflict

Post by Steve »

Hi Ondra,

Just to let you know, it's Easter weekend now and our work is shut until Tuesday - so you might not get a swift reply.

I'd look into it myself, but I do not have access to Flowcode or the hardware to look at the program.

I'm doing this from memory, but I think the register "pie1" contains the enable bit and the register "pir1" contains the flag bit.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Anything further on this?

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Program conflict

Post by Benj »

Hello Ondra

According to the device datasheet (available from Microchip.com) the interrupt enable bit is RCIE and is found in the pie1 register, the interrupt flag bit is RCIF and is available in the pir1 register.

You also need to enable Interrupts via settings bits GIE and PIE in the intcon register.

I think you will also have to make sure thet the incoming buffer is not full. Eg perform a couple of dummy read statements and then enable the interrupt.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Thanks Benj.
I made the changes as you suggested and the custom serial interrupt is working. Two question though.
1) Is there a way to know how many time I should do a read to be certain that the buffer is cleared. I got this from the data sheet. "The FIFO buffering
allows reception of two complete characters and the start of a third character before software must start servicing the EUSART receiver."
Does this mean that if I do a read of the input 3 times at startup that that would be enough to clear the buffer?
2) I have 2 interrupts one TMR0 at 75mhz and one custom. The TMR0 calls a macro that update a byte var. I have a loop in main that checks the status of the variable and calls a time update macro and flashes an LED. My serial interrupt has a RS232 receive component macro, with a decision Icon->Data=255?, which calls my bit bang out macro. By them selves both the time clock and the ->serial in - bit bang out-> work, but when I put the 2 programs together the serial is not reliable. If I type characters in fast a number of the characters don't get banged out. IF I type slow all the characters do get bang out. Take away the TMR0 program and it works fine. My thinking is that when the serial stops receiving that the TMR0 interrupt would continue from where it was before the serial receive interrupt occurred. For some reason the TMR0 is affecting the custom interrupt. I would love to get this working right. Any Idea as to what I am missing?


Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

Benj or Steve any help on the above? I've been here before. I sure could use some resolve on this.

Ondra

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: RS232 Program conflict

Post by Steve »

I'm not sure about your first point.

For the second point, it could be that the timer interrupt is interrupting the flow of data at a critical time. Whatever you do indide an interrupt should be as short as succinct as possible. Try to do as little as possible in your interrupt routines.

One good technique for doing this is to have a "flag" variable that is initially set to zero in your program. In your interrupt routine, set the flag variable to 1 if a certain condition has been met. Then, in your main loop, frequently check the value of this flag variable and react to it accordingly (i.e. do something if it is not zero). Remember to set it back to 0 once you have finished.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: RS232 Program conflict

Post by Ondra »

That did it. Thanks Steve. And about the first question I think Benj might have the answer for that. It working fine for now, if I have any other issues I guess I'll come back to the first question. Thanks again.

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Program conflict

Post by Benj »

Hello Ondra

Yes 3 read functions at the start of your program, or anywhere else in your program for that matter will completely clear the incoming UART buffer.

Post Reply