Hello, I’m trying to write a simple code to test SCI communication between two 8bit mcus, specifically a MC9S08SH8 and a MC9S08AC16, I’ve been able to verify that the transmitter is transmitting and that the receiver is realizing that there's something trying to be sent, but the SCIS1_FE flag always gets set on the receiver end.
Right now I’m trying to send a full 0xff byte, but I’ve tried with a lot of arbitrary combinations of 0's and 1's and the result is the same.
Some info that might be important:
Transmission is ocurring at 62,5 bauds, or 8MHz/(16*8000)
Both mcus are running at 8MHz but the receiver is using a crystal while the transmitter is using internal clock.
Watchdogs are disabled.
Devices were initialized by processor expert.
there are "witness" LEDS on the transmission wire and a couple more on some GPIO pins to indicate some things, mostly framing error, transmission on going and waiting.
Transmission is done by polling while reception is done by interrupts.
Interrupt vector are declared on a separate header.
Code for the transmitter:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "PTC.h"
#include "COPFree.h"
#include "SCI.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
#define L_R PTCD_PTCD0
#define L_Y PTCD_PTCD1
#define TRANSMIT_READY SCIS1_TDRE
#define TRANSMIT_FINISH SCIS1_TC
#define TRANSMIT_ENABLE SCIC2_TE
void tx_s(unsigned char s[]);
void tx_c(unsigned char cr);
unsigned char string[17] = {
0x01,
0x02,
0x04,
0x08,
0x10,
0x20,
0x40,
0x80,
0x11,
0x22,
0x44,
0x88,
0x81,
0x42,
0x24,
0x18,
'\0'
};
unsigned long j=0;
void main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
PTBDD_PTBDD7=0;
PTBDD_PTBDD5=1;
for(;;){
__asm NOP;
if(PTBD_PTBD7 == 1){
PTBD_PTBD5=0;
L_Y=1;
L_R=0;
TRANSMIT_ENABLE=1;
//tx_s( string );
SCIC2_SBK=1;
tx_c(0xff);
TRANSMIT_ENABLE=0;
}
PTBD_PTBD5=1;
L_Y=0;
L_R=1;
for(j=0;j<50000;j++){
__asm NOP;
}
}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
void tx_c(unsigned char cr){
(void)SCIS1;
SCID=cr;
}
void tx_s(unsigned char s[]){
unsigned int i=0;
unsigned long l=0;
while( s[i] != '\0' ){
if( (TRANSMIT_READY == 1) &&
(TRANSMIT_FINISH ==1) ){
tx_c(s[i]);
}
else{
//continue;
}
i++;
}
//for(l=0;l<20000;l++){
// __asm NOP;
//}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code for the receiver:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/* ###################################################################
** Filename : main.c
** Project : RXPrueba
** Processor : MC9S08AC16CFD
** Version : Driver 01.12
** Compiler : CodeWarrior HCS08 C Compiler
** Date/Time : 2019-09-29, 19:16, # CodeGen: 0
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.12
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "COPFree.h"
#include "PTE.h"
#include "SCI2.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
#define RECIVE_READY SCI2S1_RDRF
#define RECIEVE_ENABLE SCI2C2_RE
#define Enable_interrupts __asm CLI
#define Disable_interrupts __asm SEI
void rx(void);
void err(void);
void main(void)
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
__asm NOP;
PTADD_PTADD0=1;
PTADD_PTADD1=0;
PTBDD_PTBDD0=1;
Enable_interrupts;
for(;;){
PTBD_PTBD0=0;
if(PTAD_PTAD1 == 1){
RECIEVE_ENABLE=1;
PTAD_PTAD0=1;
}
__asm NOP;
}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.3 [05.09]
** for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
void rx(void){
(void)SCI2S1;
PTED = SCI2D;
__asm NOP;
RECIEVE_ENABLE=0;
PTAD_PTAD0=0;
PTBD_PTBD0=0;
}
void err(void){
(void)SCI2S1;
PTED = SCI2D;
RECIEVE_ENABLE=0;
PTAD_PTAD0=0;
PTBD_PTBD0=1;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'd like to thank you people for your help, but after some hours of work i think i've worked trough all the problems, main one was the crystal section of the circuit being damaged, i'll make sure to do more thorough testing before posting next time.
I think the transmitter is being trimmed becouse processor expert is generating some code like this:
if (*(uint8_t*)0xFFAFU != 0xFFU) { /* Test if the device trim value is stored on the specified address */
ICSTRM = *(uint8_t*)0xFFAFU; /* Initialize ICSTRM register from a non volatile memory */
ICSSC = *(uint8_t*)0xFFAEU; /* Initialize ICSSC register from a non volatile memory */
}
Wires were well connected and interrupts were ocurring, aparently the LED that i had plugged to the TX of the transmitter was draining too much current and the receiver was not being able to recognize anything but 0's, the problem now is that the reciever is receiving garbage, for example if i send 0x18 the receiver will get something like 0x2A or sometimes even 0xFF, i've been told that having no crystal on the transmitter might cause it to be useless in asyncronous comunication.
Thing is even with a USB to serial cable and RealTerm, the receiver is still receiving garbage, i tried using it "barebones" plugging the TX of the usb to serial cable to the RX of the MCU, and going through a MAX232, once with 100nf capacitors, and another try with 1uf capacitors, but to no avail.
And another weird thing is that neither the Transmitter nor the receiver are able to get their FLL's locked, i've had to comment the following lines becouse the MCUs never get past them:
// while(ICGS1_LOCK == 0U) { /* Wait */
// {asm sta SRS;} /* Reset watchdog counter */
// }
That code section simply checks to see if a trim value has been stored (any value other than $FF which is erased Flash state), and if so, loads it to the appropriate register.
So, if you haven't trimmed your MCU, nothing will happen with the IF.
Hi
Please first check that the wires are properly connected.
Also check the send device program with and scope and after that please check the receiver program if this is getting the interrupt.
Are you trimming the device that is using the internal clock?