• AVR Freaks

Hot!Enabling UART1 causes incorrect ADC initialisation

New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2020/09/27 03:43:40
  • Location: 0
  • Status: offline
2020/10/01 13:48:00 (permalink)
2 (1)

Enabling UART1 causes incorrect ADC initialisation

MCC V4.0.1
Windows 10 x64
XC V1.60
PICKit 4

I have a working project, see MyConfig(WORKS).mc3 and IDE Log(WORKS).txt.
Essentially it uses an interrupt to service sensor inputs from a BLDC motor in order to drive its phases. It also uses an ADC channel (AN8) to get the position of a potentiometer used to set it speed.

I now open MCC in order to add UART1 for use with pins RB7 (Tx) and RB8 (Rx), 9600, 8 data-bits, no parity and no flow control. After generating the new code, building and loading to the target the ADC AN8 no longer works, no longer able to set the motor speed. See MyConfig(BROKEN).mc3 and IDE Log(BROKEN).txt

When doing a diff between the source code that worked and the source code that included the UART1, register AD1CON2 is being set to 0x0000 but was previously set to 0x0414 thus ADC1 is not being configured correctly.

The diff reveals other changes also but as far as I can tell these appear to just swap the ordering of include files and various #define which amount to no change (but it is weird that it has occurred).

If I manually modify register AD1CON2 to 0x0414 after it has been initialised to 0x0000 during initialisation everything including the UART1 works as expected.

When MCC generates the new files both uart1.c and uart1.h shows failure in the output windows.
Any ideas why an unrelated register is be changed when UART1 is included in the project?



1 Reply Related Threads

    Starting Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2016/12/26 22:04:03
    • Location: 0
    • Status: offline
    Re: Enabling UART1 causes incorrect ADC initialisation 2020/10/11 21:28:24 (permalink)
    5 (1)
    There seems to be a bug in MCC tool specifically for ADC Module's AD1CON2 register where on re-opening the saved project and loading/modifying any other module resets AD1CON2 to 0x0. The  work around could be to select ADC module immediately after re-opening the saved project before making any further changes to the other modules or adding any new modules.

    Jump to:
    © 2020 APG vNext Commercial Version 4.5