This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading A/D result register and output via SBUF

Using Infineon XC866-4FR

I am trying to read two A/D channel results and printing the outputs to SBUF. The results are 255 < result6 < 32607 and result7 always 0.

Here is the code:

#include "MAIN.H"
#include <stdio.h>

ubyte result6, result7;
void message( char *pucMessage );

void MAIN_vInit(void)
{
/// Initialization of module 'GPIO'
IO_vInit();

/// Initialization of module 'UART (Serial Interface)'
UART_vInit();

/// Initialization of module 'Analog / Digital Converter (ADC)'
ADC_vInit();

// Interrupt Priority

IP = 0x00; // load Interrupt Priority Register
IPH = 0x00; // load Interrupt Priority High Register
IP1 = 0x00; // load Interrupt Priority 1 Register
IPH1 = 0x00; // load Interrupt Priority 1 High Register


// USER CODE BEGIN (MAIN_Init,3)

// USER CODE END

// globally enable interrupts
EA = 1;

} // End of function MAIN_vInit

void main(void)
{
char msg[50];

MAIN_vInit();

while(1)
{

ADC_PAGE = 0x06;
ADC_CRPR1 |= 0x40; // generate load event

while(ADC_ubBusy()); // wait until conversion complete

ADC_PAGE = 0x02;
if(ADC_RESR2L & 0x10) // check whether the result is valid
{
result6 = ADC_RESR2H; // read 8-bit result
}

PORT_PAGE = 0x00;

ADC_PAGE = 0x06;
ADC_CRPR1 |= 0x40; // generate load event

while(ADC_ubBusy()); // wait until conversion complete

ADC_PAGE = 0x02;
if(ADC_RESR3L & 0x10) // check whether the result is valid
{
result7 = ADC_RESR3H; // read 8-bit result
}

PORT_PAGE = 0x00;

sprintf(msg,"\n\n\xd %d - This is the result from Channel 6" , result6);
message(msg);

sprintf(msg,"\n\n\xd %d - This is the result from Channel 7" , result7);
message(msg);

}


} // End of function main

void message( char *pucMessage )
{
// while the character is not 0
while (*pucMessage)
{
SBUF = *pucMessage++;
while (TI == 0) {;}
TI = 0;
}
return;
}

0