Hello forum.. It's my first time programming a freescale's devices so I have a little question for all of you... I want to acquirer an analog signal and i want to transmit my results to SCI, could anyone indicate me where is my problem in my code
I'm using M68demo908gb60
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <MC9S08GB60.h> /* include peripheral declarations */
#define initSOPT 0b01110011 //COP and STOP enable controls
// ||| ||
// ||| |+-RSTPE --- Reset pin enabled
// ||| +--BKGDPE -- BKGD pin enabled
// ||+------STOPE --- STOP allowed
// |+-------COPT ---- long timeout 2^18
// +--------COPE ---- COP off
#define initICGC2 0b01110000 //Clock Generator Control 2
// |||||||| should write MFDx before ICGC1
// |||||||+-RFD0 \
// ||||||+--RFD1 --- post-PLL divider (div by 1)
// |||||+---RFD2 /
// ||||+----LOCRE --- loss of clock doesn't reset
// |||+-----MFD0 \
// ||+------MFD1 --- FLL loop multiplier N = 18x
// |+-------MFD2 /
// +--------LOLRE --- loss of lock doesn't reset
// after FLL init, LOCRE will be set to force reset on clock loss
#define initICGC1 0b00111000 //Clock Generator Control 1
// 0|||||xx this setting for 32kHz
// ||||+---OSCSTEN - don't keep osc on in stop mode
// |||+----CLKS0 \ - select FLL engaged external
// ||+-----CLKS1 / (FEE) mode
// |+------REFS ---- enable oscillator amplifier
// +-------RANGE --- 32kHz crystal
//
//
//*********************************************************************************************************************************************
//The following values has been test through communication with a PC
//except Baudrate230400 because usually PC doesn't support such high baud rate
#define Baudrate9600 0x007b; // actually 9590.634
#define Baudrate19200 0x003d; // actually 19338.492
#define Baudrate38400 0x001f; // actually 38053.161
#define Baudrate57600 0x0014; // actually 58982.400
#define Baudrate115200 0x000a; // actually 117964.800
#define Baudrate230400 0x0005; // actually 235929.600
//*********************************************************************************************************************************************
uchar ReceiveBuffer[10];
void delay(void){
uint i,j,k;
for(i=0;i<1000;i++)
for(j=0;j<500;j++)
k++;
}
//*********************************************************************************************************************************************
//SCI Init
void InitSCI1(void){
SCI2C1 = 0x00;
SCI2C3 = 0x00;
SCI2C2 = 0x00;
SCI2BD = Baudrate9600;
SCI2C1_M = 1; // nine bits
SCI2C1_PE = 1; // hardware parity enable
SCI2C2_TE = 0x01;
SCI2C2_RE = 0x01;
SCI2C2_RIE = 0x01;
}
//*********************************************************************************************************************************************
// ATDinit
void initATD(void){
ATD1PE = 0x02; //Initialize the registers for ATD
ATD1C = 0xA0; //Configure the ATD1C register for the ATD module
ATD1SC = 0x41; //Configure the ATD1SC register for the ATD module
}
//*********************************************************************************************************************************************
byte SCI1_Transmit(byte Chr){
if(!SCI2S1_TDRE) { // Is the transmitter empty?
return -1; // If no then error
}
SCI2D = (byte)Chr;
return 0; // OK
}
//******************************************************************************************************************************************
void main(void) {
//int result;
byte TransmitStatus;
SOPT = initSOPT;
ICGC2 = initICGC2;
ICGC1 = initICGC1; //32kHz -> 18.874368MHz bus rate
while(!ICGS1_LOCK); //loop until FLL locks
ICGC2_LOCRE = 1; //enable reset if ref clock fails
InitSCI1();
initATD();
EnableInterrupts; /* enable interrupts */
/* include your code here */
for(; {
// __RESET_WATCHDOG(); /* feeds the dog */
TransmitStatus = SCI1_Transmit(ATD1RH); // send data
delay();
ATD1SC = ATD1SC;
} /* loop forever */
/* please make sure that you never leave this function */
}
Hello,
With a quick perusal of your code, I can see a number of potential problem areas.
Regards,
Mac
Hello mac thanks for your observation..
Cold you please post an example how can i correct all my mistakes.
Thank CN