Jump to content

Jack Caster

Members
  • Content Count

    12
  • Joined

  • Last visited

  1. You should change the ports/pins number... Probably they are different with respect to my MSP
  2. Hi guys! I found the VT100'codes in order to blink the cursor: #define CURSOR_OFF "\33[?25l" #define CURSOR_ON "\33[?25h" Thanks to http://powwow.gforge.inria.fr/doxygen/d0/ddf/_v_t100_8_h.html! You can see also http://hackipedia.org/Protocols/Terminal,%20DEC%20VT100/html/VT100%20Escape%20Codes.html ASAP I will post my update code! Now I am very busy! Bye!
  3. Thank you for the response! I'll think about that...
  4. HI! following the spirilis's I wrote the following code, and now, the UART's ISR is as little as possible! In fact the ISR's aim is simply to wake up the MCU. In order to solve the problem relating the "boot" I decided to use the switch as a power button, it seems a good idea... Now the output is the following: The updated code is: #include "io430.h" #include #include //__________MACRO__________ //RED led on P1.0 #define LED_RED BIT0 #define LED_RED_ON (P1OUT |= BIT0) #define LED_RED_OFF (P1OUT &=!BIT0) #define LED_RED_TOGGLE (P1OUT ^= BIT0) //GREEN led on P1.1 #define LED_GREEN BIT1 #define LED_GREEN_ON (P1OUT |= BIT1) #define LED_GREEN_OFF (P1OUT &= !BIT1) #define LED_GREEN_TOGGLE (P1OUT ^= BIT1) //SWITCH on P1.2 #define SWITCH_ENABLE P1DIR &=~ BIT2 #define SWITCH_DISABLE P1DIR |= BIT2 //__________CONSTANTS__________ #define CR "\n\r" #define BUFFER_SIZE 128 //__________HEADER of FUNCTIONS__________ void init_UART(void); void init_LED(void); void init_TIMERA(void); void init_SWITCH(void); void writeChar(char ch); void writeString(char * str); //__________GLOBAL VARIABLES__________ int iterator = 0; char buffer[bUFFER_SIZE]; int bufferActualSize = 0; int bufferReadIndex = 0; int bufferWriteIndex = 0; char character; char welcome1[] = "\t*** WELCOME ***"; char welcome2[] = "Type HELP for the list of command"; char prompt[] = "msp430>> "; int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; // Basic Clock System Control 1 BCSCTL1 = CALBC1_1MHZ; // BCSCTL1 Calibration Data for 1MHz // DCO Clock Frequency Control DCOCTL = CALDCO_1MHZ; // DCOCTL Calibration Data for 1MHz //INITIAL CONFIGURATION init_LED(); //Boot with switch init_SWITCH(); __low_power_mode_0(); SWITCH_DISABLE; init_UART(); __no_operation(); //INITIAL MESSAGES writeString(welcome1); writeString(CR); writeString(welcome2); writeString(CR); writeString(prompt); while(1){ __low_power_mode_0(); // Interrupts enabled // echo character and save the string if (character != '\r') { writeChar(character); //echo if (character != '\b') { buffer[iterator] = character; iterator++; } // if } else { buffer[iterator] = '\0'; writeString(CR); if (strcmp(buffer,"help") == 0) { writeString("This is the HELP!"); writeString(CR); } //if iterator = 0; writeString(prompt); } //end if-else } //end while } // end main void init_UART(void) { // UART Mode P3SEL = BIT4 + BIT5; // USCI_A0 TXD/RXD on P3.4 & P3.5 // USCI A0 Control Register 1 UCA0CTL1 |= UCSSEL_2; // USCI 0 Clock Source 2: SMCLK // USCI A0 Baud Rate 0 & 1 UCA0BR0 = 104; // 1MHz 9600 UCA0BR1 = 0; // 1MHz 9600 // USCI A0 Modulation Control UCA0MCTL = UCBRS0; // USCI Second Stage Modulation Select 0 UCA0CTL1 &= ~UCSWRST; // USCI Software Reset: Initialize state machine // Interrupt Enable 2 IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt } #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { LED_RED_TOGGLE; character = UCA0RXBUF; __low_power_mode_off_on_exit(); } void writeChar(char ch) { while (!(IFG2 & UCA0TXIFG)); // USART1 TX buffer ready? UCA0TXBUF = ch; } void writeString(char * str) { int i; for (i = 0; i < strlen(str); i++) { writeChar(str[i]); } } void init_LED(void) { LED_RED_OFF; LED_GREEN_OFF; P1DIR = LED_RED + LED_GREEN; } void init_SWITCH(void) { SWITCH_ENABLE; P1REN = BIT2; // P1.2 pull-up/down R enabled P1OUT = BIT2; // P1.2 pull-up R enabled P1IE = BIT2; // P1.2 interrupt enabled P1IES = BIT2; // P1.2 Low edge P1IFG &=~ BIT2; // P1.2 IFG cleared } #pragma vector = PORT1_VECTOR __interrupt void Port_1 (void) { P1IFG &=! BIT2; LED_GREEN_ON; __low_power_mode_off_on_exit(); } but I have a problem to solve... I would like to store the string only if I don't type the backspace; in this case I can compare the string even if there are some typing error, but these lines seem not working: if (character != '\b') { buffer[iterator] = character; iterator++; } Can you help me? Thanks!
  5. Don't worry, actually my problem isn't how to print a string (and in oder to keep the code simple a printf() function isn't necessary) but how to print a message as soon as the serial communication begins. Up to now the message is sent by the UART, but if I don't open quickly a Putty session, I won't see it. Instead if I put a delay of 5 sec, for instance, I have the time to start Putty and see the message! It is not probably such a big deal, but for now is OK. The next step is to implement an help function that is called back by typing, for instance, the word "help". Probably I will use the strcmp command. As soon as possible I will post my progresses and I will appreciate a lot your suggestions! I want to keep things as easy as possible, and only afterwards refine the code. I know that some of you guys have already done this stuff but for me is something new and probably I don't have your same high knowledge. So it's hard to handle a full code, moreover written with a personal coding style! Thanks in advance :wave:
  6. I have just tried to print an underscore and a backspace using a while loop and it works! I don't know very well the timer's interrupts, so I don't know how to implement it in order to avoid problems on the UART's interrupts... I think the blinking cursor will be the last function which I implement. Now I'm studying your code, but there are so many functions and I am quite confused! About the welcome message issue, I have put a delay before the print function and now it works, but I'd prefer to receive a welcome as soon as Putty is started...
  7. My new thread starts here http://www.43oh.com/forum/viewtopic.php?f=10&t=3366!
  8. Hi guys, I have started to work on my little project, a simple shell to control the MSP430; as I am a beginner I would like to share my little progresses and at the same time seek for an help to solve the problems on my path. #include "io430.h" #include #include //__________MACRO__________ //RED led on P1.0 #define LED_RED BIT0 #define LED_RED_ON (P1OUT |= BIT0) #define LED_RED_OFF (P1OUT &=!BIT0) #define LED_RED_TOGGLE (P1OUT ^= BIT0) //GREEN led su P1.1 #define LED_GREEN BIT1 #define LED_GREEN_ON (P1OUT |= BIT1) #define LED_GREEN_OFF (P1OUT &= !BIT1) #define LED_GREEN_TOGGLE (P1OUT ^= BIT1) //__________HEADER of FUNCTIONS__________ void init_UART(void); void writeChar(char ch); void writeString(char * str); //__________GLOBAL VARIABLES__________ char buffer[200] = {0}; char * welcome = "Welcome"; char * prompt = "msp430>> "; int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; LED_RED_OFF; LED_GREEN_OFF; P1DIR = LED_RED + LED_GREEN; init_UART(); writeString(welcome); writeString(prompt); __low_power_mode_0(); // Interrupts enabled } void init_UART(void) { // Basic Clock System Control 1 BCSCTL1 = CALBC1_1MHZ; // BCSCTL1 Calibration Data for 1MHz // DCO Clock Frequency Control DCOCTL = CALDCO_1MHZ; // DCOCTL Calibration Data for 1MHz // UART Mode P3SEL = BIT4 + BIT5; // USCI_A0 TXD/RXD on P3.4 & P3.5 // USCI A0 Control Register 1 UCA0CTL1 |= UCSSEL_2; // USCI 0 Clock Source 2: SMCLK // USCI A0 Baud Rate 0 & 1 UCA0BR0 = 104; // 1MHz 9600 UCA0BR1 = 0; // 1MHz 9600 // USCI A0 Modulation Control UCA0MCTL = UCBRS0; // USCI Second Stage Modulation Select 0 UCA0CTL1 &= ~UCSWRST; // USCI Software Reset: Initialize state machine // Interrupt Enable 2 IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt } #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { char character; LED_RED_TOGGLE; character = UCA0RXBUF; // Echo back character if (character != 0x0D) { writeChar(character); // CR = 0x0D } else { writeChar('\n'); writeChar('\r'); //CReturn writeString(prompt); } } void writeChar(char ch) { while (!(IFG2 & UCA0TXIFG)); // USART1 TX buffer ready? UCA0TXBUF = ch; } void writeString(char * str) { int i; for (i = 0; i < strlen(str); i++) { writeChar(str[i]); } } My first problem is to find a way to make my welcome message to stay put up to when a new character is received. Up to now that is what is happening: these two lines... writeString(welcome); writeString(prompt); ...seem not to work, but instead in the very moment in which I type a character the functions work. My second question is how can I write a function which prints a blinking cursor. It seems not easy! Thank you!
  9. I have just seen the posts! There is a lot of useful information! I'll start studying! Thanks! EDIT: dacoffey, I will be your Padawan!
  10. Yes sir... I would like to create a (basic) shell in order to control some functions of the MSP430 using the terminal... why?
  11. Thank you for welcoming me!
  12. Hi guys! I am a Mechatronic Engineering student and I started working on MSP430 thanks to an Embedded Systems course. Right now I am developing a small project based on the UART communication. As I am a beginner I am having some troubles in understanding the UART and I hope that this forum could help me!
×
×
  • Create New...