1 Wire STM32

Michal Grunt michal.grunt na vynet.cz
Úterý Červenec 23 11:16:29 CEST 2013


Peru se s 1 Wire sběrnicí na STM32F0. Nějak jsem se zamotal do nastavení GPIO pro vstup a pro výstup.

Globální definice portu (pinu):
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_StructInit (&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

Vystup - funkce ow_pin_out():
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIO_OW, &GPIO_InitStructure);

Vstup - funkce ow_pin_in():
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_Init(GPIO_OW, &GPIO_InitStructure);

Reset sběrnice:
ow_pin_out();
GPIO_ResetBits(GPIOA, GPIO_Pin_3);	// uzemnit
delay_us(600);
GPIO_SetBits(GPIOA, GPIO_Pin_3);
ow_pin_in();
delay_us(150);
out = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3);
ow_pin_out();
delay_us(400);
return out;

Je to tak správně, nebo dělám někde chybu? GPIO_OType_PP/OD si nějak nejsem jistej. PullUp resistor fyzicky připojenej nemám, ten defunuji GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP.

MG


Další informace o konferenci Hw-list