Probably bug in UARTx_INIT command

General discussion on mikroBasic PRO for PIC.
Author
Message
senoleker
Posts: 28
Joined: 01 Mar 2015 18:43

Probably bug in UARTx_INIT command

#1 Post by senoleker » 05 Apr 2017 10:20

Normally, when run this code, LED will flash 10 times, then flashes forever with another style.
The problem is: that unless removing "uart1_init" command, program stops working at this point.
What is wrong?

CPU=PIC18F67K40

Code: Select all

program test
dim
  LED as sbit at LATG0_bit
  tb as byte

sub procedure Interrupt ()
  asm
    nop
  end asm
end sub

main:
  TRISG.0=0 'LED = Output
  INTCON.GIE=1
  INTCON.PEIE=1
  PIE3.TX1IE=1

  for tb=1 to 10
    LED=1
    delay_ms(50)
    LED=0
    delay_ms(50)
  next tb

  UART1_INIT(115200)
  
  while 1
    LED=1
    delay_ms(10)
    LED=0
    delay_ms(200)
  wend

end.

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Probably bug in UARTx_INIT command

#2 Post by dusan.poluga » 06 Apr 2017 14:04

Hi,

Please zip and send me your project so i can have the same setup while debugging your problem.

Regards,
Dusan Poluga.

senoleker
Posts: 28
Joined: 01 Mar 2015 18:43

Re: Probably bug in UARTx_INIT command

#3 Post by senoleker » 06 Apr 2017 14:26

Hi Dusan,
Shortened project is attached.
Possible source of problem is Interrupt. Not UART_INIT.
Nothing should happen when the attached code is run.
Because It's just an empty loop.
But, it flashing at 200 ms period.
Appearently, something outside the my control, triggering the interrupt continuously.


program test
dim
LED as sbit at LATG0_bit

sub procedure Interrupt ()
LED=1
delay_ms(100)
LED=0
delay_ms(100)
end sub

main:
TRISG.0=0 'LED = Output
INTCON.GIE=1
INTCON.PEIE=1
PIE3.TX1IE=1
TX1STA= 32 'Transmit Enable
RC1STA=128 'SPEN

while 1
wend

end.
Attachments
UART_TEST.zip
(59.73 KiB) Downloaded 149 times

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Probably bug in UARTx_INIT command

#4 Post by dusan.poluga » 07 Apr 2017 08:30

Hi,

Please place a pull down resistor on the UART lines and test it.

Regards,
Dusan Poluga.

senoleker
Posts: 28
Joined: 01 Mar 2015 18:43

Re: Probably bug in UARTx_INIT command

#5 Post by senoleker » 07 Apr 2017 09:38

dusan.poluga wrote:Hi,

Please place a pull down resistor on the UART lines and test it.

Regards,
Thank you for answer.

You mean all of the 10 pin? (RX1...RX5 and TX1...TX5)
or only TX1 pin?
Because I set only TX1IE bit.
TX2IE...TX5IE and RX1IE...RX5IE is not set.

Additional info:
This is working as it's supposed:

Code: Select all

  INTCON.GIE=1
  INTCON.PEIE=1
  PIE3.RC1IE=1 'RECEIVE enable
  TX1STA= 32
  RC1STA=128

But this NOT working as expected:

Code: Select all

  INTCON.GIE=1
  INTCON.PEIE=1
  PIE3.TX1IE=1 'TRANSMIT enable
  TX1STA= 32
  RC1STA=128

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Probably bug in UARTx_INIT command

#6 Post by janni » 07 Apr 2017 12:12

senoleker wrote:But this NOT working as expected:

Code: Select all

  INTCON.GIE=1
  INTCON.PEIE=1
  PIE3.TX1IE=1 'TRANSMIT enable
  TX1STA= 32
  RC1STA=128
And no wonder - TX1IF flag gets set when TXEN in TX1STA is set and processor gets stuck in ISR because TX1IE is set as well.

BTW, the order of instructions when setting-up interrupts is important - one should first configure interrupt sources, then clear these interrupt flags that can be cleared in software (not TXxIE), and only then enable interrupts.

senoleker
Posts: 28
Joined: 01 Mar 2015 18:43

Re: Probably bug in UARTx_INIT command

#7 Post by senoleker » 11 Apr 2017 13:32

janni wrote:And no wonder - TX1IF flag gets set when TXEN in TX1STA is set and processor gets stuck in ISR because TX1IE is set as well.

BTW, the order of instructions when setting-up interrupts is important - one should first configure interrupt sources, then clear these interrupt flags that can be cleared in software (not TXxIE), and only then enable interrupts.
There was this command before in code. Both in ISR and in main. I removed it to shorten code before sending here.
I can't understand, I added again these commands and it worked :S
Your suggestion really worked out. Thank you so much

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Probably bug in UARTx_INIT command

#8 Post by dusan.poluga » 12 Apr 2017 16:00

Hi,

I am glad the problem could get resolved.

Regards,
Dusan Poluga.

feuerwolf
Posts: 95
Joined: 09 Nov 2012 16:00
Location: Switzerland

Re: Probably bug in UARTx_INIT command

#9 Post by feuerwolf » 07 Jun 2017 10:13

Hallo,can someone provide me with (or point me to) a working UART example for PIC18F67K40 (PIC Clicker II new) ? I am totally struggeling to get that uC working properly.
1. Debugging with mikro Prog and internal Oscillator doesnt work. setting to External Oscillator debugging does work.
2. UART doesnt work at all. I think that might be a problem together with the Peripherial Pin_Select library, because i wanted to route the CLKR to an external Pin, but that doesnt work either. Input Pin register is set, but output pin register is not set (Page227 in Datasheet), using PPS library fails ...

Looks like you just initialised UART1, without remapping its pins. I found a microchip forum entry which says all pin has to be remapped before using UART
http://www.microchip.com/forums/m987824.aspx



please find attached my Project
Attachments
uCtest.zip
(95.78 KiB) Downloaded 144 times

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Probably bug in UARTx_INIT command

#10 Post by dusan.poluga » 09 Jun 2017 17:15

Hi,

Code: Select all

void main()
{
	ANSELD = 0x00;
	TRISD = 0x00;
	PPS_Mapping(_RC1,_INPUT,_RX4);
	PPS_Mapping(_RC0,_OUTPUT,_TX4_CK4);

	UART4_Remappable_Init(9600);

	while(1)
	{
		UART4_Remappable_Write_Text("Sending data\r\n");
		LATD7_bit = 1;
		Delay_ms(250);
		LATD7_bit = 0;
		Delay_ms(250);
	}
}
Here is the code for PIC18F67K40.

Best Regards,
Dusan Poluga.

feuerwolf
Posts: 95
Joined: 09 Nov 2012 16:00
Location: Switzerland

Re: Probably bug in UARTx_INIT command

#11 Post by feuerwolf » 12 Jun 2017 12:00

Hallo Dusan,
your code works fine for only one single UARt Port. When trying to initialize "all working" 1- 4 Ports mikroE Uart_remappable library doesnt work anymore!
After initialising ports 1 - 4, and streaming strings via its UARTs, all bytes go through the last initialized port.

I also had contact to Danilo Milovic from mikroE and he reported this as a bug to your developpers.
the workaround would be to set the UArt active before using it. Like:

Code: Select all

UART_Set_Active(&UART1_Remappable_Read, &UART1_Remappable_Write, &UART1_Remappable_Data_Ready, &UART1_Remappable_Tx_Idle);
UART1_Write_Text("u1\x0D");

UART_Set_Active(&UART4_Remappable_Read, &UART4_Remappable_Write, &UART4_Remappable_Data_Ready, &UART4_Remappable_Tx_Idle);
UART4_Write_Text("u4\x0D");

senoleker
Posts: 28
Joined: 01 Mar 2015 18:43

Re: Probably bug in UARTx_INIT command

#12 Post by senoleker » 14 Jun 2017 13:26

PIC18F67K40 datasheet says:

Code: Select all

• Serial Communications:
- [b]Five[/b] Enhanced USART (EUSART) with
Auto-Baud Detect, Auto-wake-up on Start.
RS-232, RS-485, LIN compatible
However, MicroBasic does not accept the baud rate parameter for UART5_INIT.

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Probably bug in UARTx_INIT command

#13 Post by dusan.poluga » 14 Jun 2017 15:57

senoleker wrote:PIC18F67K40 datasheet says:

Code: Select all

• Serial Communications:
- [b]Five[/b] Enhanced USART (EUSART) with
Auto-Baud Detect, Auto-wake-up on Start.
RS-232, RS-485, LIN compatible
However, MicroBasic does not accept the baud rate parameter for UART5_INIT.
Thank you for noticing this.
It has been reported to our developers.

Best Regards,
Dusan Poluga.

feuerwolf
Posts: 95
Joined: 09 Nov 2012 16:00
Location: Switzerland

Re: Probably bug in UARTx_INIT command

#14 Post by feuerwolf » 14 Jun 2017 17:22

It was already reported to mikroE, that the uartX_init Library function not works with UART5 of PIC18F67K40
I was able to use UART 1 - 4 with RX interrupt routines.

I also found inconsistencies in SPI library implementation. I could NOT start SPI communication, because Peripherial Pin Mapping for SPI1 (MISO) "Data In" can not be set in PPS_map library.
Also SET_ACTIVE routine is not available...

Maybe someone could try to Initi SPI and check my results. Tried to use a micro SD Clicker on and FAT32 lib, but as I wrote SPI_remappable couldnt be set.

nagyan81
Posts: 5
Joined: 27 Jun 2017 19:09

Re: Probably bug in UARTx_INIT command

#15 Post by nagyan81 » 02 Sep 2017 23:29

Hello Dusan,

Has this issue with the UART5_Init been resolved yet? I am trying to use all 5 UART port on PIC18F65K40 but the compiler (MicroPascal) does not accept baud rate parameter.

Regards,
Andras

Post Reply

Return to “mikroBasic PRO for PIC General”