LoginSignup
3
5

More than 5 years have passed since last update.

V-USBのPINアサインを変更する

Posted at

V-USBはAVRマイコンを使った工作でUSBトランシーバーの無いAtmega328などで手軽にUSBガジェットを作成出来る優れものなのですが、抵抗やツェナーダイオードなど小規模な回路が必要となり、小さく回路を纏めたい時など標準のPINアサインを変更したい時があります。
割り込みをINT0からPCINT0に変更しAtmega328のPIN14(PB0),PIN15(PB1)に変更した時の変更箇所について書き留めておきます。

変更箇所

usbconfig.hの下記の所を変更

usbconfig.h
/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME      B
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT      1
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT       0
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */

ポートとピン番号の割り当てを変更します。

usbconfig.h
/* ----------------------- Optional MCU Description ------------------------ */

/* The following configurations have working defaults in usbdrv.h. You
 * usually don't need to set them explicitly. Only if you want to run
 * the driver on a device which is not yet supported or with a compiler
 * which is not fully supported (such as IAR C) or if you use a differnt
 * interrupt than INT0, you may have to define some of these.
 */
 #define USB_INTR_CFG            PCICR
 #define USB_INTR_CFG_SET        (1 << PCIE0)
// #define USB_INTR_CFG_CLR        0
 #define USB_INTR_ENABLE         PCMSK0
 #define USB_INTR_ENABLE_BIT     PCINT0
 #define USB_INTR_PENDING        PCIFR 
 #define USB_INTR_PENDING_BIT    PCIF0
#define USB_INTR_VECTOR          PCINT0_vect
#endif /* __usbconfig_h_included__ */

割り込み関係の定義もPCINT0を使うように定義し直しますがPCINTを使うので優先順位の関係でINT割り込みは使用出来ません。
この変更でD+がPB0,D-がPB1になり縦長に実装し易くなります。

あまりコンパクトで無い実装例
SANY0063.JPG

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5