2009-05-08 02:49 AM
USART Single Wire (1-Wire) Mode
2011-05-17 04:11 AM
Hello! I'm using STM32F103RBT6 microcontroller to communicate with 1-Wire Network, which consist of temperature sensors DS18B20. In order to it efficiently, i'm using USART (USART3). All is fine with writing bit, but i have a problem with readind bit from the buf: To initiate reading bit process host master must pull down the bus for a few microseconds. Please, tell to me what i'm doing wrong. Also i want note very poor information about USART 1-Wire mode.
My code:Code:
<BR> <BR> //Init Periph Clocks <BR> RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); <BR> RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); <BR> <BR> // Configure GPIOB USART3_Tx_Pin <BR> GPIO_InitTypeDef GPIO_InitStructure; <BR> <BR> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; <BR> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; <BR> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; <BR> GPIO_Init(GPIOB, &GPIO_InitStructure); <BR> <BR> //Init USART3 <BR> USART_DeInit(USART); <BR> <BR> USART_InitTypeDef USART_InitStructure; <BR> <BR> USART_InitStructure.USART_BaudRate = 115200 ; <BR> USART_InitStructure.USART_WordLength = USART_WordLength_8b; <BR> USART_InitStructure.USART_StopBits = USART_StopBits_2; <BR> USART_InitStructure.USART_Parity = USART_Parity_No; <BR> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; <BR> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; <BR> <BR> USART_Init(USART3, &USART_InitStructure); <BR> USART_Cmd(USART3, ENABLE); <BR> USART_HalfDuplexCmd(USART3, ENABLE); <BR> <BR>//==================================================== <BR> <BR>// Reading procedure <BR> u16 nData = USART_ReceiveData(USART); <BR> <BR>
[ This message was edited by: dmitry.shpilevoy on 08-05-2009 09:42 ] [ This message was edited by: dmitry.shpilevoy on 08-05-2009 09:44 ]2011-05-17 04:11 AM
My impression is that the 1 wire USART mode is meant for a fixed master/slave relationship, such as a computer driving a printer. You have a two way relationship with your temperature sensor.
The data sheet for this device describes a specially timed initiation sequence to get communication flowing that isn't in your example code. I suggest you bit bang this interface instead of using a USART to ensure you are meeting Maxim's 1 wire bus protocol requirements. Cheers, Hal2011-05-17 04:11 AM
I check there is data to be read first:
Code:
char uart_getc(void) { while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET); return((char)USART_ReceiveData(USART1)); } Chris.2011-05-17 04:11 AM
Quote:
On 08-05-2009 at 11:59, Anonymous wrote: I check there is data to be read first: [code] .... Chris. Thank you, for your reply, but IMHO it's not sutable for 1-Wire Networks, cause bus master initiates reading from devices, so USART_FLAG_RXNE will be always in RESET state. I need to know, does USART automatically forms start bit, when i call USART_ReceiveData(), or i must for it manualy before calling this function?