Hi.
I have some configuration problems. Could you help me out ?
I am trying to write a test softare that will echo back to my PC trought a SCI port.
I have a circuitboard allready, and the IRSCI is connected to a max232 circuit.
The ordinary SCI is reserved to another task.
Check my code below.
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
void main(void) {
int b=0;
int a=0;
DisableInterrupts;
CONFIG2 = 0x01; //Internal data bus clock
DDRC&=~(0x80); //Rx pin as input
PTC|=0x40; //Tx pin idle
DDRC|=0x40; //Tx pin as output
IRSCC1=0x00;
IRSCC2=0x00;
IRSCC3=0x00;
IRSCBR=0B00110000; // (4MHz/4)/(16*13) ~ 4800baud
IRSCC1=0x40; //Enable SCI module
IRSCC2=0x0C; //Enable Transmitter and Reveiver
EnableInterrupts;
for(; {
__RESET_WATCHDOG(); /* feeds the dog */
// A delay
for(b=0;b<100;b++) {
;
}
while((SCS1 & 0x80)==0); // Rx done ??
IRSCDR=IRSCDR; // Tx the character that is Rx.
} /* loop forever */
}
What do i wrong ?
/Alfa Master
Solved! Go to Solution.
I did as you said, check the correct flag, and added the cop reset in my loop and it worked.
I also dicovered how great the Initialize Device menu is. So i removed all my settings in the beginning and used the init function instead.
Thanks
/Terje.
Hello Alpha,
Some issues with your code -
1) You appear to be polling the SCTE flag within SCS1 register, rather than the SCRF flag within the IRSCS1 register, since you are waiting for a received character into the IRSCI module.
2) Once the correct flag is polled, it is likely that COP timeout will occur since you do not reset the COP timer within your wait loop.
while ((IRSCS1 & 0x20) == 0) // Rx done ??
__RESET_WATCHDOG();
3) It may also pay to check the code generated by the compiler for the statement -
IRSCDR = IRSCDR;
to ensure that the compiler does not optimise this away.
The code to initialise the port pins is unnecessary since the IRSCI module will over-ride these pins when the module is enabled. There also seems to be little point in first zeroing the control registers before then writing the required values.
I have not checked your baud rate calculation. However, it is possible that the binary notation may not be acceptable to all compilers. Better to use hexadecimal.
Regards,
Mac
I did as you said, check the correct flag, and added the cop reset in my loop and it worked.
I also dicovered how great the Initialize Device menu is. So i removed all my settings in the beginning and used the init function instead.
Thanks
/Terje.