Hello,
I use the DSPS sample with hardware flow control on pins :
TX : p1.0
RX : p1.2
RTS : p0.7
CTS : p0.5
I use a PAN1740 USB devkit and a pad that receive serial over bluetooth data from module.
When I plug a line (RTS or CTS) from my PIC to the module, this one crash (maybe reset) after a little time...
The code of the PIC :
inline void usart_write(char data) {
RTS = 0; // Host ready for transmit
while(CTS == 1); // Wait for device ready
while(PIR1bits.TXIF == 0); // Wait for empty buffer
TXREG = data;
while(TXSTAbits.TRMT == 0); // Wait for transmit end
RTS = 1; // Transmit end
}
RTS for PIC is an output and CTS an input.
Without flow control the pad receive wrong data because module sometime sleep.
What am I doing wrong ?
Thanks,
Morgane Vallée
Keywords:
Device:
Where did you get the define for the UART from? Are you sure you use the right ports?
TX : p1.0
RX : p1.2
RTS : p0.7
CTS : p0.5
也许这也是cariage返回?或the baudrate is not setup correctly. So there are many possible cause of failure possible. It is hard to say what it is exactly. Can you describe a bit more details?
Can you check it with Terra Term for example there is some example in this guide:
http://pideu.panasonic.de/files/Documents/WM%20Documents/PAN1740/PAN1740...
Best regards,
Ingo
For the pins config :
#define UART1_TX_PORT GPIO_PORT_1
#define UART1_TX_PIN GPIO_PIN_0
#define UART1_RX_PORT GPIO_PORT_1
#define UART1_RX_PIN GPIO_PIN_2
#define UART1_RTS_PORT GPIO_PORT_0
#define UART1_RTS_PIN GPIO_PIN_7
#define UART1_CTS_PORT GPIO_PORT_0
#define UART1_CTS_PIN GPIO_PIN_5
For the baud rate I add this :
#define UART_BAUDRATE_19K2 52
Without flow control I don't have this problem. In any case I have the CR and LF char.
I don't use the default pins.
I try with 3 and 5V.
I try with a USB FTDI UART and it's work.
This look the problem come from my PIC program, maybe my implement of flow control not too strict.
I see my implementation is the old half duplex version...
I try with the new one.
Hum, I another have a data corruption problem, maybe because I send data before module wakeup.
But the code is waiting :
inline void usart_write(char data) {
while(PIR1bits.TXIF == 0); // Wait for empty buffer
while(TXSTAbits.TRMT == 0); // Wait for transmit end
while(CTS == 1); // Wait for device ready
TXREG = data;
}
I try to add a 100µs delay before send to wait wakeup, unfortunately.
Solved, just a PIC configuration problem, need to add :
ANSELCbits.ANSC2 = 0; // Disable analog on RC2 input
The code work.