Member | Action | Date |
---|---|---|
![]() |
Replied
to
CP210x Driver v10.1.1 issue with Windows 10, build 1803
I have the same issue like Tom said. Using a Terminal program, I can choose any supported baud rate I want, but on my .NET application, Visual throws an exception that I have exceeded the maximum baud rate. |
May 08 2018, 8:23 PM |
![]() |
Voted up please_there_is_a-hRlN Show more |
May 08 2018, 8:18 PM |
![]() |
Selected an answer for
Communicating with FPGA
Problem solved
Show more
|
May 08 2018, 8:16 PM |
![]() |
Replied
to
Communicating with FPGA
Problem solved
Show more
|
May 08 2018, 8:16 PM |
![]() |
Posted
Communicating with FPGA on
Forum
Hi, I have a Xilinx SP601 Board and it has a CP2103 chip. I've programmed the FPGA to do a certain task and I want it to send information to a terminal on the PC. I am interfacing with the chip through a RS232 module in the FPGA. The board schematic shows that I can connect to following CP2103's pins: TX, RX. RTS, CTS. I am only transmitting to the PC. Few questions: How do I control the chip's baud rate? I am transmitting to the chip by asserting the CTS pin to low through the RTS port of my RS232 module, is that correct?
|
May 07 2018, 7:12 AM |
![]() |
Replied
to
Using printf and scanf
while (1) { EA = 0; // Disable interrupts SFRPAGE = UART1_PAGE; printf("Enter 'r' to read volts:\n"); key = scanf("%c",&key); // user enters his key if(key == 'r') { printf("Hello\n"); } } Just corrected a mistake and made look easier. |
Oct 28 2017, 1:57 PM |
![]() |
Posted
Using printf and scanf on
Forum
Hello,
The code: Notice what I am doing in main(): //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include <c8051f120.h> // SFR declarations #include <stdio.h> //----------------------------------------------------------------------------- // 16-bit SFR Definitions for 'F12x //----------------------------------------------------------------------------- sfr16 ADC0 = 0xbe; // ADC0 data //Timer 2 is used for Milliseconds delay sfr16 RCAP2 = 0xca; // Timer2 capture/reload sfr16 TMR2 = 0xcc; // Timer2 //Timer 3 is used for ADC0 sfr16 RCAP3 = 0xca; //Timer3 capture/reload sfr16 TMR3 = 0xcc; //Timer3 //----------------------------------------------------------------------------- // Global Constants //----------------------------------------------------------------------------- //Clocks #define BAUDRATE 128000 // Baud rate of UART in bps #define SYSCLK 49000000 // SYSCLK = System clock frequency in Hz //ADC parameters #define SAMPLE_RATE 50000 // Sample frequency in Hz #define INT_DEC 256 // Integrate and decimate value #define SAR_CLK 2500000 // Desired SAR clock speed #define SAMPLE_DELAY 50 // Delay in ms before taking sample //bits sbit LED = P1^6; // LED='1' means ON sbit SW1 = P3^7; //----------------------------------------------------------------------------- // Function Prototypes //----------------------------------------------------------------------------- void OSCILLATOR_Init (void); void PORT_Init (void); void UART1_Init (void); void ADC0_Init (void); void TIMER3_Init (int counts); void ADC0_ISR (void); //void Wait_MS (unsigned int ms); //----------------------------------------------------------------------------- // Global Variables //----------------------------------------------------------------------------- long Result; //ADC0 decimate value char key[5]; //ASCII key int argsread; //Characters read from stream //----------------------------------------------------------------------------- // main() Routine //----------------------------------------------------------------------------- void main (void) { long measurement; // Measured voltage in mV WDTCN = 0xde; // Disable watchdog timer WDTCN = 0xad; OSCILLATOR_Init (); // Initialize oscillator PORT_Init (); // Initialize crossbar and GPIO UART1_Init (); // Initialize UART1 TIMER3_Init (SYSCLK/SAMPLE_RATE); // Initialize Timer3 to overflow at // sample rate ADC0_Init (); // Init ADC //SFRPAGE = ADC0_PAGE; //AD0EN = 1; // Enable ADC EA = 1; // Enable global interrupts while (1) { EA = 0; // Disable interrupts // The 12-bit ADC value is averaged across INT_DEC measurements. The result is // then stored in Result, and is right-justified // The measured voltage applied to AIN 0.1 is then: // // Vref (mV) // measurement (mV) = --------------- * Result (bits) // (2^12)-1 (bits) SFRPAGE = UART1_PAGE; UART1_Init (); printf("Enter 'r' to read volts:\n"); UART1_Init (); key = scanf("%c",&key); // user enters his key //SFRPAGE=ADC0_PAGE; if(key == 'r') { UART1_Init (); printf("Hello\n"); //measurement = Result * 2430 / 4095; //EA = 1; // Re-enable interrupts //SFRPAGE = UART1_PAGE; //printf("AIN0.1 voltage: %ld mV\n",measurement); //SFRPAGE = CONFIG_PAGE; //LED = ~SW1; // LED reflects state of switch //Wait_MS(SAMPLE_DELAY); // Wait 50 milliseconds before taking // another sample //EA=0; } } } //----------------------------------------------------------------------------- // Initialization Subroutines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // OSCILLATOR_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function initializes the system clock to use the PLL as its clock // source, where the PLL multiplies the external 22.1184MHz crystal by 9/4. // //----------------------------------------------------------------------------- void OSCILLATOR_Init (void) { int loop; // Software timer char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; // Set SFR page OSCICN = 0x83; // Set internal oscillator to run // at its maximum frequency CLKSEL = 0x00; // Select the internal osc. as // the SYSCLK source //Turn on the PLL and increase the system clock by a factor of M/N = 2 SFRPAGE = CONFIG_PAGE; PLL0CN = 0x00; // Set internal osc. as PLL source SFRPAGE = LEGACY_PAGE; FLSCL = 0x10; // Set FLASH read time for 50MHz clk // or less SFRPAGE = CONFIG_PAGE; PLL0CN |= 0x01; // Enable Power to PLL PLL0DIV = 0x01; // Set Pre-divide value to N (N = 1) PLL0FLT = 0x01; // Set the PLL filter register for // a reference clock from 19 - 30 MHz // and an output clock from 45 - 80 MHz PLL0MUL = 0x02; // Multiply SYSCLK by M (M = 2) for (loop=0; loop < 256; loop++); // Wait at least 5us PLL0CN |= 0x02; // Enable the PLL while(!(PLL0CN & 0x10)); // Wait until PLL frequency is locked CLKSEL = 0x02; // Select PLL as SYSCLK source SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // PORT_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function configures the crossbar and GPIO ports. // // P0.4 digital push-pull UART TX // P0.5 digital open-drain UART RX // P1.6 digital push-pull LED // AIN0.1 analog Analog input (no configuration necessary) //----------------------------------------------------------------------------- void PORT_Init (void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; // set SFR page XBR0 = 0x00; XBR1 = 0x00; XBR2 = 0x44; // Enable crossbar and weak pull-up // Enable UART1 P0MDOUT |= 0x01; // Set TX1 pin to push-pull P1MDOUT |= 0x40; // Set P1.6(LED) to push-pull SFRPAGE= SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // UART1_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // Configure the UART1 using Timer1, for <baudrate> and 8-N-1. // //----------------------------------------------------------------------------- void UART1_Init (void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = UART1_PAGE; SCON1 = 0x10; // SCON1: mode 0, 8-bit UART, enable RX SFRPAGE = TIMER01_PAGE; TMOD &= ~0xF0; TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload if (SYSCLK/BAUDRATE/2/256 < 1) { TH1 = -(SYSCLK/BAUDRATE/2); CKCON |= 0x10; // T1M = 1; SCA1:0 = xx } else if (SYSCLK/BAUDRATE/2/256 < 4) { TH1 = -(SYSCLK/BAUDRATE/2/4); CKCON &= ~0x13; // Clear all T1 related bits CKCON |= 0x01; // T1M = 0; SCA1:0 = 01 } else if (SYSCLK/BAUDRATE/2/256 < 12) { TH1 = -(SYSCLK/BAUDRATE/2/12); CKCON &= ~0x13; // T1M = 0; SCA1:0 = 00 } else { TH1 = -(SYSCLK/BAUDRATE/2/48); CKCON &= ~0x13; // Clear all T1 related bits CKCON |= 0x02; // T1M = 0; SCA1:0 = 10 } TL1 = TH1; // Initialize Timer1 TR1 = 1; // Start Timer1 SFRPAGE = UART1_PAGE; TI1 = 1; // Indicate TX1 ready SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // ADC0_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // Configure ADC0 to use Timer3 overflows as conversion source, to // generate an interrupt on conversion complete, and to use right-justified // output mode. Enables ADC end of conversion interrupt. Leaves ADC disabled. // //----------------------------------------------------------------------------- void ADC0_Init (void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = ADC0_PAGE; ADC0CN = 0x04; // ADC0 disabled; normal tracking // mode; ADC0 conversions are initiated // on overflow of Timer3; ADC0 data is // right-justified REF0CN = 0x07; // Enable temp sensor, on-chip VREF, // and VREF output buffer AMX0CF = 0x00; // AIN inputs are single-ended (default) AMX0SL = 0x01; // Select AIN0.1 pin as ADC mux input ADC0CF = (SYSCLK/SAR_CLK) << 3; // ADC conversion clock = 2.5MHz ADC0CF |= 0x00; // PGA gain = 1 (default) EIE2 |= 0x02; // enable ADC interrupts SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // TIMER3_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : // 1) int counts - calculated Timer overflow rate // range is postive range of integer: 0 to 32767 // // Configure Timer3 to auto-reload at interval specified by <counts> (no // interrupt generated) using SYSCLK as its time base. // //----------------------------------------------------------------------------- void TIMER3_Init (int counts) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = TMR3_PAGE; TMR3CN = 0x00; // Stop Timer3; Clear TF3; TMR3CF = 0x08; // use SYSCLK as timebase RCAP3 = -counts; // Init reload values TMR3 = RCAP3; // Set to reload immediately EIE2 &= ~0x01; // Disable Timer3 interrupts TR3 = 1; // start Timer3 SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // Interrupt Service Routines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // ADC0_ISR //----------------------------------------------------------------------------- // // Here we take the ADC0 sample, add it to a running total <accumulator>, and // decrement our local decimation counter <int_dec>. When <int_dec> reaches // zero, we post the decimated result in the global variable <Result>. // //----------------------------------------------------------------------------- void ADC0_ISR (void) interrupt 15 { static unsigned int_dec=INT_DEC; // Integrate/decimate counter // we post a new result when // int_dec = 0 static long accumulator=0L; // Here's where we integrate the // ADC samples AD0INT = 0; // Clear ADC conversion complete // indicator accumulator += ADC0; // Read ADC value and add to running // total int_dec--; // Update decimation counter if (int_dec == 0) // If zero, then post result { int_dec = INT_DEC; // Reset counter Result = accumulator >> 8; accumulator = 0L; // Reset accumulator } } //----------------------------------------------------------------------------- // Support Subroutines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Wait_MS //----------------------------------------------------------------------------- // // Return Value : None // Parameters: // 1) unsigned int ms - number of milliseconds of delay // range is full range of integer: 0 to 65335 // // This routine inserts a delay of <ms> milliseconds. // //----------------------------------------------------------------------------- /*void Wait_MS(unsigned int ms) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = TMR2_PAGE; TMR2CN = 0x00; // Stop Timer3; Clear TF3; TMR2CF = 0x00; // use SYSCLK/12 as timebase RCAP2 = -(SYSCLK/1000/12); // Timer 2 overflows at 1 kHz TMR2 = RCAP2; ET2 = 0; // Disable Timer 2 interrupts TR2 = 1; // Start Timer 2 while(ms) { TF2 = 0; // Clear flag to initialize while(!TF2); // Wait until timer overflows ms--; // Decrement ms } TR2 = 0; // Stop Timer 2 SFRPAGE = SFRPAGE_SAVE; // Restore SFRPAGE }*/ //----------------------------------------------------------------------------- // putchar //----------------------------------------------------------------------------- // /* Copyright KEIL ELEKTRONIK GmbH 1990 - 2002 */ /* * putchar (basic version): expands '\n' into CR LF */ // Modified by BW // // This routine overloads the standard putchar() library function to support // either UART0 or UART1, depending on the state of the global variable // <Uart>. // char putchar (char c) { char SFRPAGE_SAVE = SFRPAGE; SFRPAGE = UART1_PAGE; if (c == '\n') // If carriage return { while (!TI0); TI0 = 0; SBUF1 = 0x0d; // Output CR } while (!TI0); // Wait for transmit complete TI0 = 0; SBUF1 = c; // Send character SFRPAGE = SFRPAGE_SAVE; return c; } //----------------------------------------------------------------------------- // _getkey //----------------------------------------------------------------------------- // /* Copyright KEIL ELEKTRONIK GmbH 1990 - 2002 */ // Modified by BW // // This routine overloads the standard _getkey() library function to support // either UART0 or UART1, depending on the state of the global variable // <Uart>. // char _getkey () { char c; char SFRPAGE_SAVE = SFRPAGE; SFRPAGE = UART1_PAGE; while (!RI0); // Wait for byte to be received RI0 = 0; c = SBUF1; // Read the byte SFRPAGE = SFRPAGE_SAVE; return (c); } //----------------------------------------------------------------------------- // End Of File //-----------------------------------------------------------------------------
This is what the user see:
Thanks, any enlightenment would be appreciated. |
Oct 28 2017, 1:57 PM |