Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
et:examples:communication:bluetooth:eunistone [2012/10/22 10:53] rellermaaet:examples:communication:bluetooth:eunistone [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 6: Line 6:
 [LIB] [[et:software:homelab:library:usart]], \\  [LIB] [[et:software:homelab:library:usart]], \\ 
 [LIB] [[et:software:homelab:library:module:lcd_graphic]] \\  [LIB] [[et:software:homelab:library:module:lcd_graphic]] \\ 
 +
 +**BTBee Pro mooduli puhul vaata siia:**
 +[[et/examples/communication/bluetooth/btbee|BTBee Pro moodul]] \\
 +**Bluetooth Bee mooduli puhul vaata siia:**
 +[[et/examples/communication/bluetooth|Bluetooth Bee moodul]]
 + \\
 + \\
 +**Täielik AT käskude nimekiri (en):** \\ 
 +[[http://www.cooking-hacks.com/skin/frontend/default/cooking/pdf/Bluetooth_SPP_AT_SW_description.pdf|AT käsustik]]
 +
  
  ===== Teooria =====  ===== Teooria =====
  
-{{  ::examples:communication:bt.jpg?220|BT moodul.}}+{{  ::examples:communication:bluetoothboard.png?220|BT moodul}}
  
 Bluetooth on tööstusstandard seadmete omavaheliseks traadita ühenduseks. Selle eesmärgiks on juhtmeühenduste asendamine mobiiltelefonide, arvutite jt. suhtlemisel perifeeriaseadmetega. Bluetooth on tööstusstandard seadmete omavaheliseks traadita ühenduseks. Selle eesmärgiks on juhtmeühenduste asendamine mobiiltelefonide, arvutite jt. suhtlemisel perifeeriaseadmetega.
Line 31: Line 41:
 Kui ühendus on loodud virtuaalse jadaliidese abil, siis on võimalik arvutist saata Hyper Terminali vms. kaudu andmeid Bluetooth Bee vahendusel kontrollerile. Kui ühendus on loodud virtuaalse jadaliidese abil, siis on võimalik arvutist saata Hyper Terminali vms. kaudu andmeid Bluetooth Bee vahendusel kontrollerile.
  
-Järgnev kood selgitab mooduli kasutamist analoogselt ZigBee näitele. Siin seatakse Bluetooth Bee ülemaks seadmeks (seda on vaja teha ainult esimesel korralnagu ka pin-koodi, mooduli nime jm. seadete sisestust) ja luuakse selle abil ühendus mõne muu seadmega. +Järgnev kood näitab lühidaltkuidas luua ühendus Kodulabori kontrolleri ning arvuti vahel.
 <code c> <code c>
 +#define F_CPU 14745600
 +
 +#include <homelab/pin.h>
 +#include <homelab/delay.h>
 +#include <homelab/module/lcd_gfx.h>
 +#include <homelab/usart.h>
 +
 +//
 +// Select USART channel
 +usart port = USART(1);
 +
 +//
 +// Initialize bluetooth module
 +//
 +uint8_t Bluetooth_Connect() 
 +{
 + char dump;
 + char str[10];
 + _delay_ms(500);
 + lcd_gfx_clear();
 + // Software reset
 + do
 + {
 + while(usart_has_data(port))
 + dump = usart_read_char(port);
 + usart_send_string(port,"AT+JRES\r\n");
 + while(!usart_has_data(port));
 + usart_read_string(port,str,5);
 + lcd_gfx_write_string(str);
 + } while (strcmp(str,"ROK"));
 +
 + // set request password 123456
 + while(usart_has_data(port))
 + dump = usart_read_char(port);
 + usart_send_string(port,"AT+JSEC=3,1,1,06,123456\r\n");
 + while(!usart_has_data(port));
 + usart_read_string(port,str,4);
 + lcd_gfx_write_string(str);
 + if (strcmp(str,"OK") != 0)
 + return 0;
 +
 + // Set to discoverable
 + while(usart_has_data(port))
 + dump = usart_read_char(port);
 + usart_send_string(port,"AT+JDIS=3\r\n");
 + while(!usart_has_data(port));
 + usart_read_string(port,str,4);
 + lcd_gfx_write_string(str);
 + if (strcmp(str,"OK") != 0)
 + return 0;
 +
 + // Register local services
 + while(usart_has_data(port))
 + dump = usart_read_char(port);
 + usart_send_string(port,"AT+JRLS=1101,11,Serial Port,01,000000\r\n");
 + while(!usart_has_data(port));
 + usart_read_string(port,str,5);
 + lcd_gfx_write_string(str);
 + if (strcmp(str,"OK") != 0)
 + return 0;
 +
 + // Auto accept all connection requests
 + while(usart_has_data(port))
 + dump = usart_read_char(port);
 + usart_send_string(port,"AT+JAAC=1\r\n");
 + while(!usart_has_data(port));
 + usart_read_string(port,str,5);
 + lcd_gfx_write_string(str);
 + if (strcmp(str,"OK") != 0)
 + return 0;
 +
 + // Connect using password 123456
 + while(usart_has_data(port))
 + dump = usart_read_char(port);
 + usart_send_string(port,"AT+JPCR=06,123456\r\n");
 + while(!usart_has_data(port));
 + usart_read_string(port,str,5);
 + lcd_gfx_write_string(str);
 + if (strcmp(str,"OK") != 0)
 + return 0;
 +
 + while( UCSR1A & (1<<RXC1) )
 + dump = UDR1;
 +
 + return 1;
 +}
 +
 +//
 +// Put bluetooth module in transparent mode
 +//
 +uint8_t Bluetooth_transparent() 
 +{
 + char str[50];
 +
 + do
 + {
 + usart_has_data(port);
 + usart_read_string(port,str,50);
 + }while(!strstr(str,"+RSLE"));
 + usart_send_string(port,"AT+JSCR\r\n");
 +}
  
 +//
 +// Main program
 +//
 +int main(void)
 +{
 + char text[15];
 + char dump;
 + char c;
 + int a = 0;
 + int connect = 0;
 +
 + // Initialize LCD
 + lcd_gfx_init();
 + lcd_gfx_clear();
 +
 + // Initialize USART
 + usart_init_async(port, USART_DATABITS_8,
 + USART_STOPBITS_ONE,
 + USART_PARITY_NONE,
 + USART_BAUDRATE_ASYNC(115200));
 +
 + lcd_gfx_write_string("Reset:");
 + //Connect to Bluetooth on PC
 + while(!Bluetooth_Connect());
 +
 + lcd_gfx_clear();
 + lcd_gfx_goto_char_xy(0,1);
 + lcd_gfx_write_string("Connect me...");
 +
 + //Wait for terminal connection from PC
 + Bluetooth_transparent();
 +
 + //Connection established, run rest of program.
 + lcd_gfx_clear();
 + lcd_gfx_goto_char_xy(0,0);
 + lcd_gfx_write_string("Connected");
 + lcd_gfx_goto_char_xy(0,1);
 + lcd_gfx_write_string("Terminal text is mirrored toterminal and  LCD; + sign   clears screen ");
 + while(1)
 + {
 + //Read USART data and mirror it to LCD and back to the terminal
 + while(!(UCSR1A & (1<<RXC1)));
 + dump = UDR1;
 + //If '+' character is sent, clear LCD screen
 + if(dump == '+')
 + lcd_gfx_clear();
 + else
 + {
 + lcd_gfx_write_char(dump);
 + usart_send_char(port,dump);
 + }
 + }
 +}
 </code> </code>
et/examples/communication/bluetooth/eunistone.1350903185.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0