samna_asadi
Junior Member level 3
- Joined
- Mar 19, 2011
- Messages
- 30
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,519
and any way is it possible to connect uart directly to fsk transmitter
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 //usart init UCSRA=0; UCSRB=0b00001000; UCSRC=0b10000110; UBRRH=0; UBRRL=207; . . . . void send_data(int data) { while ( !( UCSRA & (1<<UDRE)) ); UDR=255; // just for identifying the right transmitter while ( !( UCSRA & (1<<UDRE)) ); UDR=140; // just for identifying the right transmitter while ( !( UCSRA & (1<<UDRE)) ); UDR=data; while ( !( UCSRA & (1<<UDRE)) ); UDR=140; // just for identifying the right transmitter } and in the whole code of the receiver side: #define F_CPU 1000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #define R_enable PORTD |= 2; #define R_disable PORTD &= ~2; #define green_on PORTC |= 4; #define green_off PORTC &= ~4; #define yellow_on PORTC |= 16; #define yellow_off PORTC &= ~16; int data,os=0; void run(); int main(void) { DDRD=226; DDRC=255; DDRB=255; PORTC=255; PORTB=255; PORTD=28; UCSRA=0; UCSRB=0b10010000; UCSRC=0b10000110; UBRRH=0; UBRRL=25; green_off; yellow_off; R_enable; sei(); while(1) { } } ISR(_VECTOR(11)) { switch (os) { case 0: { if(UDR==255) { os=1; green_on; } else green_off; break; } case 1: { if(UDR==140) { os=2; yellow_on; } else { os=0; yellow_off; } break; } case 2: { data=UDR; os=3; break; } case 3: { if(UDR==140) { run(); } os=0; break; } } } void run() { PORTD = (PORTD & 31) | (data << 5); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 /* * girande_termometer.cpp * * Created: 7/21/2013 10:04:55 PM * Author: saman */ #define F_CPU 1000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #define R_enable PORTD |= 2; #define R_disable PORTD &= ~2; #define green_on PORTC |= 4; #define green_off PORTC &= ~4; #define yellow_on PORTC |= 16; #define yellow_off PORTC &= ~16; int data,os=0,stat; void run(); int main(void) { DDRD=226; DDRC=255; DDRB=255; PORTC=255; PORTB=255; PORTD=28; UCSRA=0; UCSRB=0b10010000; UCSRC=0b10000110; UBRRH=0; UBRRL=25; green_off; yellow_off; R_enable; sei(); while(1) { if((PIND & 4)==0 && stat==1) { stat=0; PORTD=((PORTD & 223) | (~PORTD & 32)); } if((PIND & 8)==0 && stat==1) { stat=0; PORTD=((PORTD & 191) | (~PORTD & 64)); } if((PIND & 16)==0 && stat==1) { stat=0; PORTD=((PORTD & 127) | (~PORTD & 128)); } if((PIND & 28)==28) { stat=1; } // if((PORTD & 32)==32){yellow_on;} // else yellow_off; // if((PORTD & 64)==64){green_on;} // else green_off; } } ISR(_VECTOR(11)) { switch (os) { case 0: { if(UDR==255) { os=1; green_on; } else green_off; break; } case 1: { if(UDR==140) { os=2; yellow_on; } else { os=0; yellow_off; } break; } case 2: { data=UDR; os=3; break; } case 3: { if(UDR==140) { run(); } os=0; break; } } } void run() { PORTD = (PORTD & 31) | (data << 5); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 while(1) { if((PINC & 16)==0 && (stat3==2) && (stat ==1)) { _delay(50); if((PINC & 16)==0 && (stat3==2) && (stat ==1)) { myflag1 = 1; } } if(myflag){ stat=0; stat3=0; if(rm>=1) { if(rm==1) { if(u[13]>=1)u[13]=0; else u[13]=1; screen(15); send_data(); } } else { flash=1; if(mode>=1)screen(mode-1); mode++; if(mode>=12) { mode=0; TCCR2=0x05; writeee(200); flash=1; LCDClear(); reset_screen(); } else TCCR2=0x03; screen(mode-1); } myflag1 = 0; } if((PINC & 32)==0 && (stat==1) && (stat3>=1)) { _delay_ms(50); if((PINC & 32)==0 && (stat==1) && (stat3>=1)) { myflag2 = 1; } } if(myflag2){ stat=0; stat3=0; if(rm>=1) { if(rm==1) { if(u[13]==1)u[13]=2; else u[13]=1; screen(15); send_data(); } if(rm==2) { if(u[15]>=3)u[15]=0; else u[15]++; screen(16); } } else { altm=0; if(mode==0) { u[8]+=10; calc_at(); screen(11); if(u[8]>180) { u[8]=0; u[10]=0; screen(12); screen(6); screen(7); LCDWriteStringXY(12,1," "); } else { u[10]=1; screen(12); screen(11); } } else { dt_set(2); screen(mode-1); } } myflag2 = 0; } if((PINC & 8)==0 && (stat==1) && (stat3==2)) { _delay_ms(50); if((PINC & 8)==0 && (stat==1) && (stat3==2)) { myflag3 = 1; } } if(myflag3){ stat=0; stat3=0; if(rm>=1) { if(rm==1) { if(u[14]==1)u[14]=0; else u[14]=1; screen(15); send_data(); } if(rm==2) { if(u[15]<=0)u[15]=3; else u[15]--; screen(16); } } else { if(mode==0) { if(datemode==0) { datemode=1; date_mode(1); } else { datemode=0; date_mode(0); } } else { dt_set(1); screen(mode-1); } } myflag3 = 0; } if((PINC & 4)==0 && (stat==1) && (stat3==2)) { _delay_ms(50); if((PINC & 4)==0 && (stat==1) && (stat3==2)) { myflag4 = 1); } } if(myflag4){ stat3=0; stat=0; if(mode==0) { switch (rm) { case 0: { rm=1; screen(15); break; } case 1: { rm=2; screen(16); break; } case 2: { rm=0; reset_screen(); writeee(15); break; } } } else { if(u[10]==1)u[10]=0; else u[10]=1; screen(12); } } if((PINC & 60) == 60)//if buttons are not pressed { stat=1; stat2=0; } else //if any button is been hold { led=0; if(u[9]>=1)led_on(); if(u[9]==0)led_off(); } } }
Pulldown Tx of transmitter and Rx of receiver. Add a 100 nF Capacitor close to VCC and GND pins of Transmitter and receiver RF modules.
Use this code if PORTC of transmitter has buttons. To better help post Schematic or Proteus file.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 while(1) { if((PINC & 16)==0 && (stat3==2) && (stat ==1)) { _delay(50); if((PINC & 16)==0 && (stat3==2) && (stat ==1)) { myflag1 = 1; } } if(myflag){ stat=0; stat3=0; if(rm>=1) { if(rm==1) { if(u[13]>=1)u[13]=0; else u[13]=1; screen(15); send_data(); } } else { flash=1; if(mode>=1)screen(mode-1); mode++; if(mode>=12) { mode=0; TCCR2=0x05; writeee(200); flash=1; LCDClear(); reset_screen(); } else TCCR2=0x03; screen(mode-1); } myflag1 = 0; } if((PINC & 32)==0 && (stat==1) && (stat3>=1)) { _delay_ms(50); if((PINC & 32)==0 && (stat==1) && (stat3>=1)) { myflag2 = 1; } } if(myflag2){ stat=0; stat3=0; if(rm>=1) { if(rm==1) { if(u[13]==1)u[13]=2; else u[13]=1; screen(15); send_data(); } if(rm==2) { if(u[15]>=3)u[15]=0; else u[15]++; screen(16); } } else { altm=0; if(mode==0) { u[8]+=10; calc_at(); screen(11); if(u[8]>180) { u[8]=0; u[10]=0; screen(12); screen(6); screen(7); LCDWriteStringXY(12,1," "); } else { u[10]=1; screen(12); screen(11); } } else { dt_set(2); screen(mode-1); } } myflag2 = 0; } if((PINC & 8)==0 && (stat==1) && (stat3==2)) { _delay_ms(50); if((PINC & 8)==0 && (stat==1) && (stat3==2)) { myflag3 = 1; } } if(myflag3){ stat=0; stat3=0; if(rm>=1) { if(rm==1) { if(u[14]==1)u[14]=0; else u[14]=1; screen(15); send_data(); } if(rm==2) { if(u[15]<=0)u[15]=3; else u[15]--; screen(16); } } else { if(mode==0) { if(datemode==0) { datemode=1; date_mode(1); } else { datemode=0; date_mode(0); } } else { dt_set(1); screen(mode-1); } } myflag3 = 0; } if((PINC & 4)==0 && (stat==1) && (stat3==2)) { _delay_ms(50); if((PINC & 4)==0 && (stat==1) && (stat3==2)) { myflag4 = 1); } } if(myflag4){ stat3=0; stat=0; if(mode==0) { switch (rm) { case 0: { rm=1; screen(15); break; } case 1: { rm=2; screen(16); break; } case 2: { rm=0; reset_screen(); writeee(15); break; } } } else { if(u[10]==1)u[10]=0; else u[10]=1; screen(12); } } if((PINC & 60) == 60)//if buttons are not pressed { stat=1; stat2=0; } else //if any button is been hold { led=0; if(u[9]>=1)led_on(); if(u[9]==0)led_off(); } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 ISR(_VECTOR(11)) { switch (os) { case 0: { if(UDR==255) { os=1; green_on; } else{ green_off; os = 0; } break; } case 1: { if(UDR==140) { os=2; yellow_on; } else { os=0; yellow_off; } break; } case 2: { data=UDR; os=3; break; } case 3: { if(UDR==140) { PORTD = (PORTD & 31) | (data << 5); } os=0; break; } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 /* * girande_termometer.cpp * * Created: 7/21/2013 10:04:55 PM * Author: saman */ #define F_CPU 1000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #define R_enable PORTD |= 2; #define R_disable PORTD &= ~2; #define green_on PORTC |= 4; #define green_off PORTC &= ~4; #define yellow_on PORTC |= 16; #define yellow_off PORTC &= ~16; int data,os=0,stat; unsigned char uart_rd[4], disp, index = 0; void run(); int main(void) { DDRD=226; DDRC=255; DDRB=255; PORTC=255; PORTB=255; PORTD=28; UCSRA=0; UCSRB=0b10010000; UCSRC=0b10000110; UBRRH=0; UBRRL=25; green_off; yellow_off; R_enable; sei(); while(1) { if((PIND & 4)==0 && stat==1) { stat=0; PORTD=((PORTD & 223) | (~PORTD & 32)); } if((PIND & 8)==0 && stat==1) { stat=0; PORTD=((PORTD & 191) | (~PORTD & 64)); } if((PIND & 16)==0 && stat==1) { stat=0; PORTD=((PORTD & 127) | (~PORTD & 128)); } if((PIND & 28)==28) { stat=1; } // if((PORTD & 32)==32){yellow_on;} // else yellow_off; // if((PORTD & 64)==64){green_on;} // else green_off; if(disp){ if((uart_rd[0] == 255) { green_on; } else{ green_off; } if((uart_rd[1] == 140) { yellow_on; } else { yellow_off; } if((uart_rd[3] == 140) { PORTD = (PORTD & 31) | (uart_rd[2] << 5); } disp = 0; uart_rd[0] = 0; uart_rd[1] = 0; uart_rd[2] = 0; uart_rd[3] = 0; } } } ISR(_VECTOR(11)) { uart_rd[index++] = UDR; if(index == 4){ index = 0; disp = 1; } }
Send the dsn files. You have sent Layout files. The link you provided doesn't have datasheet(s). There is no snubber network for relays. Relays are close to RF module. Change the placement of RF module on your receiver board. Most probably there is EMI between relay and RF receiver module. When you connect through wires you are not experiencing this. To test remove rf module from board and use 15 cm wires to connect receiver module to PCB. If it solves the problem then you have to change the layout of your PCB and place RF module away from power and other electromagnetic devices.
I don't see RF Tx module on Tx board. Use crystal if dealing with UART or precise timing. You have used Internal RC Oscillator of 8 MHz in transmitter.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?