Hi guys,
I am trying to develop X10 433Mhz RF transmitter using USART2. Basically, I am using a transmitter module from RF solutions RTFQ1-433Mhz. It has an Enable Pin, which I am connecting to VCC of Primer to maintain a Logic one, and INPUT Pin is connected to USART2.
I am initializing the USART2 Pin and enabling it but when I debug it I cant get anything. can someone please help its ma project else I will fail for sure.... heres the code.
//USART initialization
#include "ut2.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_conf.h"
#include "stm32f10x_lib.h"
#include "circle_api.h"
#include "stm32f10x_map.h"
#define _USART2
#ifdef _USART2
#define USART2 ((USART_TypeDef *) USART2_BASE)
#endif  
void InitUSART()
{
 
 
 GPIO_InitTypeDef  GPIO_InitStructure;
  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE); 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
    
  /* USART2 configuration ------------------------------------------------------*/
  /* USART2 configured as follow:
        - BaudRate = 9600 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
        - USART Clock disabled
        - USART CPOL: Clock is active low
        - USART CPHA: Data is captured on the second edge 
        - USART LastBit: The clock pulse of the last data bit is not output to 
                         the SCLK pin
  */
  USART_InitTypeDef USART_InitStructure; 
  
  USART_InitStructure.USART_BaudRate = 9600;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No ;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx;
  
  USART_Init(USART2, &USART_InitStructure); 
 
  /* Enable the USART2 */
 USART_Cmd(USART2, ENABLE);  
}
I am not quiet sure whether I need Hardware Flow control.... I think yes... Is that a prob?
//main code...... Here I am worried about delays.....
#include "stm32f10x_lib.h"
#include "x10a.h"
#include "circle_api.h"
#include "stm32f10x_conf.h"
#include "stm32f10x_map.h"
#include "ut2.h"
#define Bit_SET 1
#define Bit_RESET 0
#define _USART2
#ifdef _USART2
#define USART2 ((USART_TypeDef *) USART2_BASE)
#endif /*_USART2 */
/************************************************************************************
*Function name: x10_sendpreamble
*Description: sends 1 for 9msec & 0 for 4.5msec
*Input: None
*Output: None
*Return :None
*****************************************************************************/
void x10_sendpreamble()
{
USART_SendData(USART2, Bit_RESET);
 /*delay_ms(40); */
USART_SendData(USART2, Bit_SET);
 /* delay_ms(8);*/
USART_SendData(USART2, Bit_RESET);
 /* delay_ms(4); */
}
// In X10 if the bit to be send is 1 only 1 is send but if its 0 then 1 and 0 is sent. Eg. to send 5 which is 101 we will have to send 1101.
void x10_sendbit(int thebit)
{ 
 
    {
if(thebit==0)
    
{ 
USART_SendData(USART2, Bit_SET);
/* delay_us(400);*/
USART_SendData(USART2, Bit_RESET);
/* delay_us(700);*/
}
else    
{ 
USART_SendData(USART2, Bit_SET);
/* delay_us(400);*/
USART_SendData(USART2, Bit_SET);
delay_us(400);
}
}
return;
}
void x10_sendbyte(int thebyte)
{
int i;
for (i=0;i<8;i++)
{
x10_sendbit(thebyte<<2);
}
return;
}
void x10_send(char hc, int unit, int action) 
{
int ufcbyte; // unit function code
x10_sendpreamble();
// here we set the house code
if (unit > 8) { hc=0b00000100; } else { hc=0b00000000; }
switch (hc) 
{
case 'P':  hc=hc|0b00110000; break;  
case 'O':  hc=hc|0b00100000; break; 
case 'N':  hc=hc|0b00010000; break; 
case 'M':  hc=hc|0b00000000; break; 
case 'L':  hc=hc|0b11010000; break; 
case 'K':  hc=hc|0b11000000; break; 
case 'J':  hc=hc|0b11110000; break; 
case 'I':  hc=hc|0b11100000; break; 
case 'H':  hc=hc|0b10110000; break; 
case 'G':  hc=hc|0b10100000; break; 
case 'F':  hc=hc|0b10010000; break; 
case 'E':  hc=hc|0b10000000; break; 
case 'D':  hc=hc|0b01010000; break; 
case 'C':  hc=hc|0b01000000; break; 
case 'B':  hc=hc|0b01110000; break; 
case 'A':
default:   hc=hc|0b01100000; break; 
}
x10_sendbyte(hc); 
x10_sendbyte(~hc);
// send the house code and its inverse
                    // here, we set the unit and function code bits 
switch (action) {     // need to support dim/bright
case 0: { ufcbyte=0b10000111; break; } // on
case 1: { ufcbyte=0b10100111; break; } // off
default: { ufcbyte=0b11111111; break; } // A1on
}
switch (unit) {
case 8:
case 16: { ufcbyte=ufcbyte|0b01011000; break; }
case 7:
case 15: { ufcbyte=ufcbyte|0b01001000; break; }
case 6:
case 14: { ufcbyte=ufcbyte|0b01010000; break; }
case 5:
case 13: { ufcbyte=ufcbyte|0b01000000; break; }
case 4:
case 12: { ufcbyte=ufcbyte|0b00011000; break; }
case 3:
case 11: { ufcbyte=ufcbyte|0b00001000; break; }
case 2:
case 10: { ufcbyte=ufcbyte|0b00010000; break; }
case 1:
case 9: default: { ufcbyte=ufcbyte|0b00000000; break; }
}
x10_sendbyte(ufcbyte);
x10_sendbyte(~ufcbyte);
// send the unit/function code and inverse
x10_sendbit(1); // gratuitous 1 at the end…
    
 return;
}
//------------------- 
void delay_ms(int n)
{ 
//delay n ms 
unsigned int x; 
  while(n--)
  { 
    x=2300;       
    while(x--); 
  } 
} 
//------------------- 
void delay_us(int n)
{ 
//delay n 100us 
unsigned int x; 
n=n/1000;
  while(n--)
  { 
    x=230; 
    while(x--); 
  } 
}
Please help me guys......... would really appreciate it.....
					Last edited by pitu82 (2009-05-22 16:57:37)