214 Views 1 Replies Last post: Jan 29, 2010 12:22 PM by bchussey RSS
Knut Pacholke Newbie 1 posts since
Sep 29, 2009
Currently Being Moderated

Jan 26, 2010 8:48 AM

Spi communication on UART4

hello,

i use the r32c111 starter kit and i want to use the txd4,rxd4 and clk 4 to communicate via spi. i initialize the ports but no clock signals come out of clk4

the initializing is like this

/*””FUNC COMMENT””**************************************************************
* Outline   : SPI_Master_init
* Description  : Configures UART4 in transmit mode
* Argument   : none
* Return value  : none
*””FUNC COMMENT END””**********************************************************/

void SPI_Master_init(void)
{
/* Configure pin p9_5 as follows - CLK4, Output pin   */
pd9_5 = 1;
p9_5s = 0x3;

/* Configure pin p9_7 as follows - RXD4, Input pin   */
pd9_7 = 0;

/* Configure pin p6_3 as follows - TXD4, Output pin   */
pd9_6 =  1;
p9_6s = 0x3;

   

/* Configure pin p9_4 as follows - Output port pin (to select slave device) */
p9_4 = 0;
pd9_4 = 1;
p9_4s = 0;
 
/* Set master clock bit rate. Please refer to the macro BIT_RATE in the
    header file for actual bit rate  */
u4brg = (unsigned char)(((f1_CLK_SPEED)/(2*BIT_RATE))-1);

/* UART4 transmit/receive mode register
   b2:b0 - SMD2:SMD0  - 001 (serial synchronous interface mode selected)
      b3 - CKDIR   - 0 (Internal clock selected)
      b4 - STPS   - 0 (1 Stop bit)
      b5 - PRY   - 0 (No parity used)
      b6 - PRYE   - 0 (No parity used)
     b7 - IOPOL   - 0 (TXD, RXD polarity not inverted)  */
 
u4mr = 0x01;
   
/* UART0 transmit/receive control register 0
   b1:b0 - CLK01:CLK0 - 00 (U0BRG count source select bits -f1 selected)
      b2  - CRS    - 0 (CTS/RTS function select bit (Set to 0))
     b3 - TXEPT   - 0 (Clear transmit register empty flag)
      b4 - CRD   - 1 (Disable CTS/RTS function)
      b5 - NCH   - 0 (N-channel open drain output selected)
      b6 - CKPOL   - 1 (Transmit data is output at the rising edge of
           transmit/receive clock and receive data is input at
         the falling edge.
     b7 - UFORM   - 1 (MSB first selected) */
 
   u4c0 = 0xd0;
   
    u4brg = (unsigned char)(((f1_CLK_SPEED)/(2*BIT_RATE))-1);

/* UART0 transmit/receive control register 1
      b0  - TE  - 1 (Enable transmission)
   b1  - TI   - 0 (Clear the 'transmit buffer empty' flag)
   b2  - RE   - 1 (Enable reception)
   b3  - RI  - 0 (Clear the 'Receive complete' flag)
   b4  - UiIRS     - 0
   b5 - UiRRM  - 1 (Use continuous receive )
   b7:b6 - Reserved - 00 (Set to 00) */
 
   u4c1 = 0x25; 

/* Unused in synchronous serial mode. Set to 0. */
u4smr = 0x00;

/* Unused in synchronous serial mode. Set to 0. */
u4smr2 = 0x00;

/* UART4 Special Mode Register 3
    b0  SSE   -1 (SS0n pin enabled)  
    b1  CKPH   -0 (No delayed clock)
    b2  DINC  -0 (set to 0 in master mode)
    b3  NODC   -0 (CLKi pin in N-channel open drain output)
    b4   ERR   -0 (set to 0 )
    b7:b5  DL2:DL0  -000 (Select as 0 in serial synchronous mode) */
   
u4smr3 = 0x09;

/* Unused in synchronous serial mode. Set to 0. */
u4smr4 = 0x00;

/* Disable interrupts */
DISABLE_IRQ

/* Interrupt Control Register for UART0 transmit
b2:b0  - ILVL2:ILVL0  - 011 (Interrupt priority 3 selected for UART0
           transmit)
b3   - IR    - 0 (Interrupt request bit. Set to 0)
b4   - POL    - 0 (Polarity select bit. Set to 0.) 
b5   - Reserved  - 0
b7:b6  - Reserved  - 0   */
 
s4tic = 0x03;

/* Enable interrupts */
ENABLE_IRQ


}

so i write to the txd4 in a loop

 

/* This loop should never exit.  */
while (1)
{
     //p9_5 = 0;
  //for (ucLoopcnt=0; ucLoopcnt<sizeof(c_data); ucLoopcnt++)
     {
     
   while(ti_u4c1 == 0)
      {
       /* Wait for previous transmission to complete */
      }    

       /* Load the data to be transmitted, in the transmit buffer */
      //u4tb = (short) c_data[ucLoopcnt];
   u4tb = 0xAA;
   //pd9_5 = 1;
   //p9_5 = 1;
  
      }
};

 

no clock signal come out of port clk4.

i hope anyone can help me to solve the problem

 

regards

 

knut

bchussey Newbie 7 posts since
Mar 3, 2009
Currently Being Moderated
Jan 29, 2010 12:22 PM in response to: Knut Pacholke
Re: Spi communication on UART4

From looking at the code it looks like you are not disabling write protection on the PD9 and P9_iS registers.  If you look in section 10 (Protection) at the PRCR register you will see the bit PRC2.  Unless you set this bit to 1, you cannot write PD9 or P9_iS (i = 3 to 7).  Also, you have to set this bit to 1 every time you write to one of these registers becasue after a write it automatically sets the PRC2 bit back to 0 (write disabled).  So your code would look something like this:

 

    /* pin settings for making pin p9_6 as transmitter pin of UART4 (output function select) */
    prc2 = 1;
    p9_6s = 0x03;
   
    /* pin settings for making pin p9_6 as transmitter pin of UART4 (direction register) */           
    prc2 = 1;
    pd9_6 = 1;

    /* pin settings for making pin p9_7 as receiver pin of UART4 */
    prc2 = 1;
    pd9_7 = 0;

 

    etc... for CLK4 and so on.

More Like This

  • Retrieving data ...

Bookmarked By (0)