Hi everybody, I am learning to program with MCUs and now i have got the SK-XC164 board.I am trying to transmit via ASC0 a message. This message has 6 equal bytes and I must do it with transmit interrupt. Has anyone a simple program to practise??. The message I would like to see the message through Hyperterminal on PC. Thanks to everyone.
Thanks Chris, I have just tested your program example and It only sends me 1 "Hello" and not 5.(txSendCount = 5; /* set the number of bytes to send */). What can I do?
How many bytes are in "Hello"?
Hello Chris. You are right. The example works well. Thank you very mutch. :D
Hello Chris, I would like to get more information about these instructions: ASC0_TBIC_IR, ASC0_TBIC and the rest of code relationed with ASC0. I want to know where do you get them from. I saw the XC164CS complet datasheet and I haven't seen them. Thanks
Hi John,
You can find the information in the peripheral users manual. Look in the ASC section under interrupts.
TBIR is activated when data is moved from TBUF to the transmit shift register.
TIR is activated before the last bit of an asynchronous frame is transmitted, or after the last bit of a synchronous frame has been transmitted
So if you are sending a stream of data generally you would use the TBIR as this could keep the transmission to appear to be contiguous. It allows the register to be loaded while still sending a value.
You generally would use the TIR interrupt if you need to perform software handshaking.
Hope that helps. -Chris
Sorry, I didn't read your last post correctly.
ASC0_TBIC_IR is the interrupt flag in the special function register (SFR) ASC0_TBIC that would get set when the transmit buffer is able to accept another word.
It is automatically cleared when you vector its interrupt handler. Alternatively you can clear it by software.
Look at both the system and peripheral users manuals for information about interrupts.
I have understood the reply and it's been important. One more thing. Could you give me a program that is similar to transmission interrupt, but in this case using reveive interrupt? Thank you very much, Chris.
I have tried sending a "A" character via HyperTerminal to the XC164CS and when it receives, it blinks a LED. I use this code, but it doesn't run correctly.
#include <AR166.h> #include <XC164.h> unsigned char mi_sbuf; void main(void) { ASC0_CON = 0x0011; // load ASC0 control register ASC0_BG = 0x0011; // load ASC0 baud rate time reload register ALTSEL0P3 |= 0x0400; /* select alternate output function */ _bfld_(P3,0x0C00,0x0400); /* P3.10 (Tx) and P3.11 (Rx) are used */ _bfld_(DP3,0x0C00,0x0400); /* P3.10 (Tx) and P3.11 (Rx) are used */ ASC0_TXFCON = 0x0100; /* transmit FIFO is disabled */ /// ASC0_TBIC = 0x0079; ASC0_RIC = 0x007D; ASC0_CON |= 0x8000; // enable baud rate generator while (1); } void ASC0_viRx(void) interrupt ASC0_RINT using RB_LEVEL15 { while (ASC0_RIC_IR); mi_sbuf = ASC0_RBUF; if (mi_sbuf == 'A') { if (MY_LED == 0)MY_LED = 1; else MY_LED=0; os_dly_wait (50); if (MY_LED == 0)MY_LED = 1; else MY_LED=0; os_dly_wait (50); } }
Hello Chris, I fixed the problem removing the "os_dly_wait(50)" function (C166 compliler especial function). :D Thanks everybody for your attention
Hello, Could anyone tell me the differences between using transmit interrupt and transmit buffer interrupt? What are the pros and cons of each? Thanks.
You can get an interrupt when the UART can accept more characters. This allows you to keep it constantly running, where the transmitted characters comes almost immediately after each other.
You can get an interrupt when the UART runs dry. This allows you to manually toggle handshake signals or turn off power to transceiver chips etc in between characters. But on the other hand, there will be a bit longer pause until you will manage to send one more character.
If you run a packet-based protocol, you normally want to keep the UART running continuously until the packet ends.
If you run a char-by-char protocol or have multiple masters connected on a bus, you must be able to immediately detect and react to a bus collision.
Hello, can anyone help me to initialize the PORT3 for ASC1 pins Tx, Rx? Thanks
I am exasperated :( . I tried to do the same program that Chis did, but this time using ASC1, and it doesn't work. Probably i have wrong the initialization of ASC1. Can you help me Chris? Thank you very much
I hope you are using the right vector to handle your communication? that would be required if you changed to ASC1.
How do I know if I am using the right handle? The ASC0 and ASC1 are supossed to be equal, aren't they? Thanks for reply.
well, look in your data sheet. I assume each of these peripherals has its own interrupt vector. you need to change the number of your interrupt service routine to handle ASC1 rather than ASC0.