Home ] Up ]
 
  BV4206 GPIO  
 

Contained within this html page are scripts that will work in conjunction with the VB4221. The BV4221 is a USB to I2C converter so that by connecting the BV4221 to the PC and also to one or more I2C devices, it is possible to control them from this browser document.

There are several documents in the series all of which concentrate on one particular I2C device, the first green and second blue forms are for communicating with the BV4221 and any form or text that follows is for the particular device in question. This text uses BV scripts and so depending on how the browser is configured there may be security warnings. Feel free to view the scripts and use as you like in your own applications.

Because VBScript is used then an IE (Microsoft) compatible browser is required. VBscript can also be made to run stand alone and within Microsoft applications such as Excel and Word. The script in this file should run with little modification.

 
     
  Open COM Port  
  The 'Open Port' button opens the COM port and checks the BV4221 is connected, it will not show an error if the wrong com port is chosen but will indicate if the correct port has been chosen and the BV4221 is connected.
Open COM Port
Com Port Number 1-5:      Port Settings:

   
 
     
  I2C System Commands  
  The next section is common to all I2C BV devices and can be used to interrogate the EEPROM and change the address etc. You will see that address 0 of the EEPROM is the device address.
Common BV, I2C System Functions
<< set device address Firmware version >>
From #Bytes Results
When writing separate hex with comma, e.g. 0a,9,fd,0,3
 From Data
The reset button will just reset but the factory button installs defaults ** Note the address is set back to 0x42 as well.
<< new address EVEN numbers only
 
     

  BV4206 General Purpose Input / Output  
   
     
  GPIO Section  
 
BV4206 GPIO Section, example ports 0 to 5 
 
Enable Weak pull ups on 0,1,7,8,12,13,14

Port 0

Input

 

Port 1

Input  
Output

High Lo

Output High Lo

Port 2

Input

 

Port 3

Input  
Output

High Lo

Output High Lo

Port 4

Input

 

Port 5

Input  
Output

High Lo

Output High Lo

Port 6

Input

 

Port 7

Input  
Output

High Lo

Output High Lo

Port 8

Input

 

Port 9

Input  
Output

High Lo

Output High Lo

Port 10

Input

 

Port 11

Input  
Output

High Lo

Output High Lo

Port 12

Input

 

Port 13

Input  
Output

High Lo

Output High Lo

Port 14

Input

 

 
Output

High Lo

 
 
 
     
  Timer Section  
 
Timer on pin 6 Enable:
Timer Source: Internal Osc. Pin 17
Pre-scale Value    0-7
Timer Value         0-230
>>

There is a timer that can be driven from an external source or the internal 2MHz oscillator. The value of the timer register can be read from the I2C bus or the output can be fed to an external pin. The external pin will toggle at each overflow of the register.

The timer is working all of the time but by default it is set to get it’s input from pin 17 so reading the timer value with command 13 will not reveal any changes unless there is some change on pin 17 which is set to input at reset.

The timer consists of an 8 bit register and an 8 bit presaler. The values of the prescaler can be set to the following:

Value

Rate

0

1:2

1

1:4

2

1:8

3

1:16

4

1:32

5

1:64

6

1:128

7

1:256

8

Off (1:1)

Note that value 8 will turn off the prescaler and allow the clock source to go straight to the timer counter.

The timer value can be loaded with any value from 0 to 230. This value is loaded into the counter which then increments until it overflows at value 255. At this point, if set the output at pin 6 will toggle and the value will be loaded into the timer again.

The result of this is that a value of 0 will give the largest delay (lowest frequency) and 230 will give the highest delay.

Prescale

Timer

Period

at 6

8

230

50uS

8

0

275uS

7

0

65mS

This table gives some examples of the output at pin 6 when the internal clock is used. The period is one full cycle, i.e. pin 6 goes from low to high and then back to low.

See the scope output: this is for the lowest frequency when the prescaler is set at 7 and the timer is set to 0. The period shown in Figure 2 is 65mS.

Command 13 will automatically set pin 6 (i/o 3) to be an output and using command 2 to set it either high or low will make no difference.