سلام
من hmtr دارم
همه می دونیم که hmtr با5 ولت و xmega با 3.3 ولت کار می کنه
خب حالامن می خوام که این دوتا رو بهم وصل کنم
این سوال رو تو حل مشکل xmega با سایر قطعات پرسیدم پس خواهش می کنم آدرس اون تاپیک رو ندید
دوستان اونجا گفتن که هیچ مشکلی نیست و ارتباط بدون هیچ واسطی برقرار می شه
اما من هرچی تلاش می کنم هیچی نمیشه
یعنی وقتی آیسی رو وصل می کنم به hmtr همه چراغاش خاموش می شه اما هیچی ارسال نمی کنه
مشکل از ارسال یوسارت آیسی نیست؟؟؟؟
راستی مگا 16 هم اطلاعاتش رو دریافت نمی کرد
[/code]
من hmtr دارم
همه می دونیم که hmtr با5 ولت و xmega با 3.3 ولت کار می کنه
خب حالامن می خوام که این دوتا رو بهم وصل کنم
این سوال رو تو حل مشکل xmega با سایر قطعات پرسیدم پس خواهش می کنم آدرس اون تاپیک رو ندید
دوستان اونجا گفتن که هیچ مشکلی نیست و ارتباط بدون هیچ واسطی برقرار می شه
اما من هرچی تلاش می کنم هیچی نمیشه
یعنی وقتی آیسی رو وصل می کنم به hmtr همه چراغاش خاموش می شه اما هیچی ارسال نمی کنه
مشکل از ارسال یوسارت آیسی نیست؟؟؟؟
راستی مگا 16 هم اطلاعاتش رو دریافت نمی کرد
کد:
// PORTE initialization // OUT register PORTE.OUT=0x08; // Bit0: Input // Bit1: Input // Bit2: Input // Bit3: Output // Bit4: Input // Bit5: Input // Bit6: Input // Bit7: Input PORTE.DIR=0x08; // Bit0 Output/Pull configuration: Totempole/No // Bit0 Input/Sense configuration: Sense both edges // Bit0 inverted: Off // Bit0 slew rate limitation: Off PORTE.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit1 Output/Pull configuration: Totempole/No // Bit1 Input/Sense configuration: Sense both edges // Bit1 inverted: Off // Bit1 slew rate limitation: Off PORTE.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit2 Output/Pull configuration: Totempole/No // Bit2 Input/Sense configuration: Sense both edges // Bit2 inverted: Off // Bit2 slew rate limitation: Off PORTE.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit3 Output/Pull configuration: Totempole/No // Bit3 Input/Sense configuration: Sense both edges // Bit3 inverted: Off // Bit3 slew rate limitation: Off PORTE.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit4 Output/Pull configuration: Totempole/No // Bit4 Input/Sense configuration: Sense both edges // Bit4 inverted: Off // Bit4 slew rate limitation: Off PORTE.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit5 Output/Pull configuration: Totempole/No // Bit5 Input/Sense configuration: Sense both edges // Bit5 inverted: Off // Bit5 slew rate limitation: Off PORTE.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit6 Output/Pull configuration: Totempole/No // Bit6 Input/Sense configuration: Sense both edges // Bit6 inverted: Off // Bit6 slew rate limitation: Off PORTE.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit7 Output/Pull configuration: Totempole/No // Bit7 Input/Sense configuration: Sense both edges // Bit7 inverted: Off // Bit7 slew rate limitation: Off PORTE.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Interrupt 0 level: Disabled // Interrupt 1 level: Disabled PORTE.INTCTRL=(PORTE.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) | PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc; // Bit0 pin change interrupt 0: Off // Bit1 pin change interrupt 0: Off // Bit2 pin change interrupt 0: Off // Bit3 pin change interrupt 0: Off // Bit4 pin change interrupt 0: Off // Bit5 pin change interrupt 0: Off // Bit6 pin change interrupt 0: Off // Bit7 pin change interrupt 0: Off PORTE.INT0MASK=0x00; // Bit0 pin change interrupt 1: Off // Bit1 pin change interrupt 1: Off // Bit2 pin change interrupt 1: Off // Bit3 pin change interrupt 1: Off // Bit4 pin change interrupt 1: Off // Bit5 pin change interrupt 1: Off // Bit6 pin change interrupt 1: Off // Bit7 pin change interrupt 1: Off PORTE.INT1MASK=0x00; // PORTF initialization // OUT register PORTF.OUT=0x00; // Bit0: Input // Bit1: Input // Bit2: Input // Bit3: Input // Bit4: Input // Bit5: Input // Bit6: Input // Bit7: Input PORTF.DIR=0x00; // Bit0 Output/Pull configuration: Totempole/No // Bit0 Input/Sense configuration: Sense both edges // Bit0 inverted: Off // Bit0 slew rate limitation: Off PORTF.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit1 Output/Pull configuration: Totempole/No // Bit1 Input/Sense configuration: Sense both edges // Bit1 inverted: Off // Bit1 slew rate limitation: Off PORTF.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit2 Output/Pull configuration: Totempole/No // Bit2 Input/Sense configuration: Sense both edges // Bit2 inverted: Off // Bit2 slew rate limitation: Off PORTF.PIN2CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit3 Output/Pull configuration: Totempole/No // Bit3 Input/Sense configuration: Sense both edges // Bit3 inverted: Off // Bit3 slew rate limitation: Off PORTF.PIN3CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit4 Output/Pull configuration: Totempole/No // Bit4 Input/Sense configuration: Sense both edges // Bit4 inverted: Off // Bit4 slew rate limitation: Off PORTF.PIN4CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit5 Output/Pull configuration: Totempole/No // Bit5 Input/Sense configuration: Sense both edges // Bit5 inverted: Off // Bit5 slew rate limitation: Off PORTF.PIN5CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit6 Output/Pull configuration: Totempole/No // Bit6 Input/Sense configuration: Sense both edges // Bit6 inverted: Off // Bit6 slew rate limitation: Off PORTF.PIN6CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit7 Output/Pull configuration: Totempole/No // Bit7 Input/Sense configuration: Sense both edges // Bit7 inverted: Off // Bit7 slew rate limitation: Off PORTF.PIN7CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Interrupt 0 level: Disabled // Interrupt 1 level: Disabled PORTF.INTCTRL=(PORTF.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) | PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc; // Bit0 pin change interrupt 0: Off // Bit1 pin change interrupt 0: Off // Bit2 pin change interrupt 0: Off // Bit3 pin change interrupt 0: Off // Bit4 pin change interrupt 0: Off // Bit5 pin change interrupt 0: Off // Bit6 pin change interrupt 0: Off // Bit7 pin change interrupt 0: Off PORTF.INT0MASK=0x00; // Bit0 pin change interrupt 1: Off // Bit1 pin change interrupt 1: Off // Bit2 pin change interrupt 1: Off // Bit3 pin change interrupt 1: Off // Bit4 pin change interrupt 1: Off // Bit5 pin change interrupt 1: Off // Bit6 pin change interrupt 1: Off // Bit7 pin change interrupt 1: Off PORTF.INT1MASK=0x00; // PORTR initialization // OUT register PORTR.OUT=0x00; // Bit0: Input // Bit1: Input PORTR.DIR=0x00; // Bit0 Output/Pull configuration: Totempole/No // Bit0 Input/Sense configuration: Sense both edges // Bit0 inverted: Off // Bit0 slew rate limitation: Off PORTR.PIN0CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Bit1 Output/Pull configuration: Totempole/No // Bit1 Input/Sense configuration: Sense both edges // Bit1 inverted: Off // Bit1 slew rate limitation: Off PORTR.PIN1CTRL=PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc; // Interrupt 0 level: Disabled // Interrupt 1 level: Disabled PORTR.INTCTRL=(PORTR.INTCTRL & (~(PORT_INT1LVL_gm | PORT_INT0LVL_gm))) | PORT_INT1LVL_OFF_gc | PORT_INT0LVL_OFF_gc; // Bit0 pin change interrupt 0: Off // Bit1 pin change interrupt 0: Off PORTR.INT0MASK=0x00; // Bit0 pin change interrupt 1: Off // Bit1 pin change interrupt 1: Off PORTR.INT1MASK=0x00; } // Virtual Ports initialization void vports_init(void) { // PORTA mapped to VPORT0 // PORTB mapped to VPORT1 PORTCFG.VPCTRLA=PORTCFG_VP1MAP_PORTB_gc | PORTCFG_VP0MAP_PORTA_gc; // PORTC mapped to VPORT2 // PORTD mapped to VPORT3 PORTCFG.VPCTRLB=PORTCFG_VP3MAP_PORTD_gc | PORTCFG_VP2MAP_PORTC_gc; } // USARTE0 initialization void usarte0_init(void) { // Note: the correct PORTE direction for the RxD, TxD and XCK signals // is configured in the ports_init function // Transmitter is enabled // Set TxD=1 PORTE.OUTSET=0x08; // Communication mode: Asynchronous USART // Data bits: 8 // Stop bits: 1 // Parity: Disabled USARTE0.CTRLC=USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc; // Receive complete interrupt: Disabled // Transmit complete interrupt: Disabled // Data register empty interrupt: Disabled USARTE0.CTRLA=(USARTE0.CTRLA & (~(USART_RXCINTLVL_gm | USART_TXCINTLVL_gm | USART_DREINTLVL_gm))) | USART_RXCINTLVL_OFF_gc | USART_TXCINTLVL_OFF_gc | USART_DREINTLVL_OFF_gc; // Required Baud rate: 9600 // Real Baud Rate: 9601.0 (x1 Mode), Error: 0.0 % USARTE0.BAUDCTRLA=0xF5; USARTE0.BAUDCTRLB=((0x0C << USART_BSCALE_bp) & USART_BSCALE_gm) | 0x0C; // Receiver: On // Transmitter: On // Double transmission speed mode: Off // Multi-processor communication mode: Off USARTE0.CTRLB=(USARTE0.CTRLB & (~(USART_RXEN_bm | USART_TXEN_bm | USART_CLK2X_bm | USART_MPCM_bm | USART_TXB8_bm))) | USART_RXEN_bm | USART_TXEN_bm; } // Receive a character from USARTE0 #pragma used+ char getchar_usarte0(void) { char data; unsigned char status; while (1) { while (((status=USARTE0.STATUS) & USART_RXCIF_bm) == 0); data=USARTE0.DATA; if ((status & (USART_FERR_bm | USART_PERR_bm | USART_BUFOVF_bm)) == 0) return data; } } #pragma used- // Write a character to the USARTE0 Transmitter #pragma used+ void putchar_usarte0(char c) { while ((USARTE0.STATUS & USART_DREIF_bm) == 0); USARTE0.DATA=c; } #pragma used- // Function used to read the calibration byte from the // signature row, specified by 'index' #pragma optsize- unsigned char read_calibration_byte(unsigned char index) { unsigned char r; NVM.CMD=NVM_CMD_READ_CALIB_ROW_gc; r=*((flash unsigned char*) index); // Clean up NVM command register NVM.CMD=NVM_CMD_NO_OPERATION_gc; return r; } #pragma optsize_default // ADCA initialization void adca_init(void) { // ADCA is enabled // Resolution: 12 Bits // Load the calibration value for 12 Bit resolution // from the signature row ADCA.CALL=read_calibration_byte(PROD_SIGNATURES_START+ADCACAL0_offset); ADCA.CALH=read_calibration_byte(PROD_SIGNATURES_START+ADCACAL1_offset); // Free Running mode: Off // Conversion mode: Unsigned ADCA.CTRLB=(ADCA.CTRLB & (~(ADC_CONMODE_bm | ADC_FREERUN_bm | ADC_RESOLUTION_gm))) | ADC_RESOLUTION_12BIT_gc; // Clock frequency: 125.000 kHz ADCA.PRESCALER=(ADCA.PRESCALER & (~ADC_PRESCALER_gm)) | ADC_PRESCALER_DIV256_gc; // Reference: Internal 1.00 V // Temperature reference: On ADCA.REFCTRL=(ADCA.REFCTRL & ((~(ADC_REFSEL_gm | ADC_TEMPREF_bm)) | ADC_BANDGAP_bm)) | ADC_REFSEL_INT1V_gc | ADC_TEMPREF_bm | ADC_BANDGAP_bm; // Initialize the ADC Compare register ADCA.CMPL=0x00; ADCA.CMPH=0x00; // ADC channel 0 gain: 1 // ADC channel 0 input mode: Single-ended positive input signal ADCA.CH0.CTRL=(ADCA.CH0.CTRL & (~(ADC_CH_START_bm | ADC_CH_GAINFAC_gm | ADC_CH_INPUTMODE_gm))) | ADC_CH_GAIN_1X_gc | ADC_CH_INPUTMODE_SINGLEENDED_gc; // ADC channel 0 positive input: ADC0 pin // ADC channel 0 negative input: GND ADCA.CH0.MUXCTRL=(ADCA.CH0.MUXCTRL & (~(ADC_CH_MUXPOS_gm | ADC_CH_MUXNEG_gm))) | ADC_CH_MUXPOS_PIN0_gc; // ADC channel 1 gain: 1 // ADC channel 1 input mode: Internal positive input signal ADCA.CH1.CTRL=(ADCA.CH1.CTRL & (~(ADC_CH_START_bm | ADC_CH_GAINFAC_gm | ADC_CH_INPUTMODE_gm))) | ADC_CH_GAIN_1X_gc | ADC_CH_INPUTMODE_INTERNAL_gc; // ADC channel 1 positive input: Temp. Reference // ADC channel 1 negative input: GND ADCA.CH1.MUXCTRL=(ADCA.CH1.MUXCTRL & (~(ADC_CH_MUXPOS_gm | ADC_CH_MUXNEG_gm))) | ADC_CH_MUXINT_TEMP_gc; // ADC channel 2 gain: 1 // ADC channel 2 input mode: Internal positive input signal ADCA.CH2.CTRL=(ADCA.CH2.CTRL & (~(ADC_CH_START_bm | ADC_CH_GAINFAC_gm | ADC_CH_INPUTMODE_gm))) | ADC_CH_GAIN_1X_gc | ADC_CH_INPUTMODE_INTERNAL_gc; // ADC channel 2 positive input: Temp. Reference // ADC channel 2 negative input: GND ADCA.CH2.MUXCTRL=(ADCA.CH2.MUXCTRL & (~(ADC_CH_MUXPOS_gm | ADC_CH_MUXNEG_gm))) | ADC_CH_MUXINT_TEMP_gc; // ADC channel 3 gain: 1 // ADC channel 3 input mode: Internal positive input signal ADCA.CH3.CTRL=(ADCA.CH3.CTRL & (~(ADC_CH_START_bm | ADC_CH_GAINFAC_gm | ADC_CH_INPUTMODE_gm))) | ADC_CH_GAIN_1X_gc | ADC_CH_INPUTMODE_INTERNAL_gc; // ADC channel 3 positive input: Temp. Reference // ADC channel 3 negative input: GND ADCA.CH3.MUXCTRL=(ADCA.CH3.MUXCTRL & (~(ADC_CH_MUXPOS_gm | ADC_CH_MUXNEG_gm))) | ADC_CH_MUXINT_TEMP_gc; // AD conversion is started by software ADCA.EVCTRL=ADC_EVACT_NONE_gc; // Channel 0 interrupt: Disabled ADCA.CH0.INTCTRL=(ADCA.CH0.INTCTRL & (~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) | ADC_CH_INTMODE_COMPLETE_gc | ADC_CH_INTLVL_OFF_gc; // Channel 1 interrupt: Disabled ADCA.CH1.INTCTRL=(ADCA.CH1.INTCTRL & (~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) | ADC_CH_INTMODE_COMPLETE_gc | ADC_CH_INTLVL_OFF_gc; // Channel 2 interrupt: Disabled ADCA.CH2.INTCTRL=(ADCA.CH2.INTCTRL & (~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) | ADC_CH_INTMODE_COMPLETE_gc | ADC_CH_INTLVL_OFF_gc; // Channel 3 interrupt: Disabled ADCA.CH3.INTCTRL=(ADCA.CH3.INTCTRL & (~(ADC_CH_INTMODE_gm | ADC_CH_INTLVL_gm))) | ADC_CH_INTMODE_COMPLETE_gc | ADC_CH_INTLVL_OFF_gc; // Enable the ADC ADCA.CTRLA|=ADC_ENABLE_bm; // Insert a delay to allow the ADC common mode voltage to stabilize delay_us(2); } // ADCA channel data read function using polled mode unsigned int adca_read(unsigned char channel) { ADC_CH_t *pch=&ADCA.CH0+channel; unsigned int data; // Start the AD conversion pch->CTRL|=ADC_CH_START_bm; // Wait for the AD conversion to complete while ((pch->INTFLAGS & ADC_CH_CHIF_bm)==0); // Clear the interrupt flag pch->INTFLAGS=ADC_CH_CHIF_bm; // Read the AD conversion result ((unsigned char *) &data)[0]=pch->RESL; ((unsigned char *) &data)[1]=pch->RESH; return data; } // ADCA sweeped channel(s) data read function // for software triggered mode void adca_sweep_read(unsigned char nch, unsigned int *pdata) { ADC_CH_t *pch=&ADCA.CH0; unsigned char i,j,m; // Sweep starts with channel 0 j=ADC_CH0START_bm; // Prepare the AD conversion start mask for the sweeped channel(s) m=0; i=0; do { m|=j; j<<=1; } while (++i<nch); // Ensure the interrupt flags are cleared ADCA.INTFLAGS=ADCA.INTFLAGS; // Start the AD conversion for the sweeped channel(s) ADCA.CTRLA=(ADCA.CTRLA & (ADC_DMASEL_gm | ADC_FLUSH_bm | ADC_ENABLE_bm)) | m; // Read and store the AD conversion results for all the sweeped channels for (i=0; i<nch; i++) { // Wait for the AD conversion to complete while ((pch->INTFLAGS & ADC_CH_CHIF_bm)==0); // Clear the interrupt flag pch->INTFLAGS=ADC_CH_CHIF_bm; // Read the AD conversion result ((unsigned char *) pdata)[0]=pch->RESL; ((unsigned char *) pdata)[1]=pch->RESH; pdata++; pch++; } } void main(void) { // Declare your local variables here unsigned char n; // Interrupt system initialization // Optimize for speed #pragma optsize- // Make sure the interrupts are disabled #asm("cli") // Low level interrupt: Off // Round-robin scheduling for low level interrupt: Off // Medium level interrupt: Off // High level interrupt: Off // The interrupt vectors will be placed at the start of the Application FLASH section n=(PMIC.CTRL & (~(PMIC_RREN_bm | PMIC_IVSEL_bm | PMIC_HILVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm))); CCP=CCP_IOREG_gc; PMIC.CTRL=n; // Set the default priority for round-robin scheduling PMIC.INTPRI=0x00; // Restore optimization for size if needed #pragma optsize_default // System clocks initialization system_clocks_init(); // Ports initialization ports_init(); // Virtual Ports initialization vports_init(); // USARTE0 initialization usarte0_init(); // ADCA initialization adca_init(); while (1) { p=251; putchar_usarte0(p); delay_ms(1000) ; } }
دیدگاه