This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART sending characters

Hello! I have a MCBSTR9 chip and i am trying to use the UART for sending some characters to the chip. All works great in simulator but when i am loading it on the chip it doesn't do anything at all. What would be the problem? Here is the source code:

/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************

/* Includes */
#include "91x_lib.h"
void init_serial (void) ;

/* Private typedef */
/* Private define */
#define TxBufferSize   (countof(TxBuffer) - 1)

/* Private macro -*/
#define countof(a)   (sizeof(a) / sizeof(*(a)))
/* Private variables */
  UART_InitTypeDef UART_InitStructure;
  u8 TxBuffer[] = "UART Example1: UART \n\r";
        u8 current;
  u8 NbrOfDataToTransfer = TxBufferSize;
  u8 TxCounter = 0;

        u32 pins[] = {
                GPIO_Pin_0,
                GPIO_Pin_1,
                GPIO_Pin_2,
                GPIO_Pin_3,
                GPIO_Pin_4,
                GPIO_Pin_5,
                GPIO_Pin_6,
                GPIO_Pin_7
        }, i, car;

/* Private function prototypes */
void SCU_Configuration(void);
void GPIO_Configuration(void);
static void Delay(u32 nCount);

* Function Name  : main
*******************************************************************************/
 u8 R;
int main()
{
  #ifdef DEBUG
    debug();
  #endif

  /* Configure the system clocks */
  SCU_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  /* UART0 configuration -*/
  /* UART0 configured as follow:
        - Word Length = 7 Bits
        - Two Stop Bit
        - No parity
        - BaudRate = 115200 baud
        - Hardware flow control enabled (RTS and CTS signals)
        - Receive and transmit enabled
        - Receive and transmit FIFOs are enabled
        - Transmit and Receive FIFOs levels have 8 bytes depth
  */
   UART_InitStructure.UART_WordLength = UART_WordLength_8D;
  UART_InitStructure.UART_StopBits = UART_StopBits_1;
  UART_InitStructure.UART_Parity = UART_Parity_No ;
   UART_InitStructure.UART_BaudRate = 9600;
   UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
   UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
   UART_InitStructure.UART_FIFO = UART_FIFO_Disable;
   UART_DeInit(UART0);
   UART_Init(UART0, &UART_InitStructure);

  /*enable UART Rx Interrupt*/
  UART_ITConfig(UART0, UART_IT_Receive  , ENABLE);

  /*configure UART0 interrupt in VIC*/
 VIC_DeInit();
 VIC_InitDefaultVectors(); /* initialize VICs default vector registers*/
 VIC_Config(UART0_ITLine, VIC_IRQ, 0);

  /* Enable the UART0 */
 UART_Cmd(UART0, ENABLE);

  /* Communication  hyperterminal-UART0 using the hardware flow control */
  /* Send a buffer from UART to hyperterminal */
  /*
        while(NbrOfDataToTransfer--)
  {
    UART_SendData(UART0, TxBuffer[TxCounter++]);
    while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET);
  }*/

  /*enable UART0 interrupt for data reception*/
  VIC_ITCmd(UART0_ITLine,ENABLE);

  while (1)
        {
                //send data
                UART_SendData(UART0, R);
                //set pins
                for(i = 0, car = (u32)R; i < 8 && car; i ++, car = car /2){
                                if(car % 2 == 1)
                                        GPIO_WriteBit(GPIO7, pins[i], Bit_SET);
                                else GPIO_WriteBit(GPIO7, pins[i], Bit_RESET);
                }
        }
}

* Function Name  : SCU_Configuration
*******************************************************************************/
void SCU_Configuration(void)
{
  SCU_MCLKSourceConfig(SCU_MCLK_OSC);   /* Default configuration */

  /*wait state insertion :This function should be executed from SRAM when*/
  /*booting from bank1 to avoid  Read-While-Write from the Same Bank.*/
  FMI_Config(FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE,\ 
                 FMI_LVD_ENABLE, FMI_FREQ_HIGH);/*Insert 2 Wait States for read*/

  SCU_PLLFactorsConfig(192, 25, 2); /* PLL factors Configuration based on*/
                                        /* a OSC/Crystal value = 25Mhz*/
  SCU_PLLCmd(ENABLE);  /* PLL Enable and wait for Locking*/
  SCU_RCLKDivisorConfig(SCU_RCLK_Div1); /* RCLK @96Mhz */
  SCU_HCLKDivisorConfig(SCU_HCLK_Div1); /* AHB @96Mhz */
  SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1);/* FMI @96Mhz */
  SCU_PCLKDivisorConfig(SCU_PCLK_Div2); /* APB @48Mhz */
  SCU_MCLKSourceConfig(SCU_MCLK_PLL);  /* MCLK @96Mhz */

  /* Enable UART0 Clock */
  SCU_APBPeriphClockConfig(__UART0, ENABLE);

  /* Enable VIC clock */
  SCU_AHBPeriphClockConfig(__VIC, ENABLE);

  /* Enable GPIO2 Clock */
  SCU_APBPeriphClockConfig(__GPIO2, ENABLE);

  /* Enable GPIO3 Clock */
  SCU_APBPeriphClockConfig(__GPIO3, ENABLE);

  /* Enable GPIO5 Clock */
  SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

}

* Function Name  : GPIO_Configuration
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
        /* GPIO Configuration */
  SCU->GPIOOUT[7]  = 0x5555;              /* P7.0..7 output - mode 1          */
  GPIO7->DDR       = 0xFF;                /* P7.0..7 Outputs (LED Data)       */

  /*Configure UART0_CTS P2.0*/
  GPIO_DeInit(GPIO2);
  /*After DeInit function P2.0 = UART0_CTS (defaut configuration)*/

  GPIO_DeInit(GPIO5);
  /*Gonfigure UART0_Rx pin GPIO5.1*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1  ;
  GPIO_Init (GPIO5, &GPIO_InitStructure);

   GPIO_DeInit(GPIO3);
  /*Gonfigure UART0_Tx pin GPIO3.4*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3  ;
  GPIO_Init (GPIO3, &GPIO_InitStructure);

  /*Gonfigure UART0_RTS pin GPIO3.3*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3  ;
  GPIO_Init (GPIO3, &GPIO_InitStructure);
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/


Thank you !

Parents Reply Children
No data