Problems with COM port on a MC908AP64A

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problems with COM port on a MC908AP64A

ソリューションへジャンプ
1,775件の閲覧回数
AlfaMaster
Contributor II

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(;:smileywink: {
    __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

ラベル(1)
0 件の賞賛
返信
1 解決策
856件の閲覧回数
AlfaMaster
Contributor II

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.

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
856件の閲覧回数
bigmac
Specialist III

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

 

0 件の賞賛
返信
857件の閲覧回数
AlfaMaster
Contributor II

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.

0 件の賞賛
返信