- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
i try to use serial port, i done this before, but it's not working in this application. Serial port interrupts doesn't launch. Here is piece of my code:
void uart0_transmit(void)
{ tx_ptr = 0;
rx_ptr = 0;
//Serial port 0 settings
UART230 |= UART230_0; // Enable high-speed baud rate generator for Serial port 0
PCON &= ~SMOD0; // Disable doubling of the baud rate for Serial port 0 (115,2K instead 230K)
SCON0 &= ~SM0_0; // Set mode 1 (01)
SCON0 |= SM0_1; // for Serial port 0
SCON0 |= REN; // Serial port 0 receive enable
SBUF0 = uart0_tx_buf[tx_ptr];
// IOA ^= LIGHT0;
}
void uart0_close(void)
{
//Serial port 0 settings
UART230 &= ~UART230_0; // Disable high-speed baud rate generator for Serial port 0
SCON0 &= ~REN; // Serial port 0 receive disable
// IOA |= LIGHT0;
}
void uart0rxtx(void) interrupt 4
{
IOA &= ~LIGHT0;
if (bit_is_set(SCON0, TI) && (tx_ptr < BYTES2TX0-1)) // Receiving-Transmitting interruption solver for uart0
{
tx_ptr += 1;
SBUF0 = uart0_tx_buf[tx_ptr]; // appending next byte to transmitt
}
SCON0 &= ~TI; // clears transmitting flag
if bit_is_set(SCON0, RI) { // Receiving flag SCON0_RI exists => cought the receiving event
uart0_rx_buf[rx_ptr] = SBUF0; // pulling received byte from uart0 buffer
rx_ptr += 1; // counting received byte
}
SCON0 &= ~RI; // clears receiption flag
}
void exchange_232_data(BYTE *buf_o, BYTE *buf_i)
{
int i, k;
unsigned long m;
for (i = 0; i < BYTES2TX0; i++) uart0_tx_buf = buf_i; // Assembling bytes to transmitt
uart0_transmit();
while (tx_ptr < BYTES2TX0 - 1) k = tx_ptr; // Waiting for the end of transmittion
m = 0;
while((rx_ptr < BYTES2RX0) & (m < WAIT_FOR_RECEIVE)) m+= 1; // Waiting for the end of receiving
if (m < WAIT_FOR_RECEIVE)
for (i = 0; i < BYTES2RX0; i++) buf_o = uart0_rx_buf; //Assembling bytes to transmitt
else
buf_o[0] = error_eb_com; // Returning the error message if receiption failed
uart0_close();
}
in main file interrupt enabled:
IE = 0x00; // Disable all interrupts
IE |= EA; // Global interrupt enable
IE |= ES0; // Enable Serial port 0 interrupt
May be i forgot something, or doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi,
Please see if AN http://www.cypress.com/?rID=39786 is useful for you. The example project attached can be referred to understand the firmware settings.
regards,
Gayathri