Skip to content

Commit e4cd8bb

Browse files
committed
Merge pull request #1266 from alexbeer2048/master
Enable LPC8xx usart when configuring it
2 parents 5b1dc60 + 37a478b commit e4cd8bb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/serial_api.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,18 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
196196
default:
197197
break;
198198
}
199-
200-
obj->uart->CFG = (data_bits << 2)
199+
200+
// First disable the the usart as described in documentation and then enable while updating CFG
201+
202+
// 24.6.1 USART Configuration register
203+
// Remark: If software needs to change configuration values, the following sequence should
204+
// be used: 1) Make sure the USART is not currently sending or receiving data. 2) Disable
205+
// the USART by writing a 0 to the Enable bit (0 may be written to the entire register). 3)
206+
// Write the new configuration value, with the ENABLE bit set to 1.
207+
obj->uart->CFG &= ~(1 << 0);
208+
209+
obj->uart->CFG = (1 << 0) // this will enable the usart
210+
| (data_bits << 2)
201211
| (paritysel << 4)
202212
| (stop_bits << 6);
203213
}

libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/serial_api.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,17 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
230230
break;
231231
}
232232

233-
obj->uart->CFG = (data_bits << 2)
233+
// First disable the the usart as described in documentation and then enable while updating CFG
234+
235+
// 24.6.1 USART Configuration register
236+
// Remark: If software needs to change configuration values, the following sequence should
237+
// be used: 1) Make sure the USART is not currently sending or receiving data. 2) Disable
238+
// the USART by writing a 0 to the Enable bit (0 may be written to the entire register). 3)
239+
// Write the new configuration value, with the ENABLE bit set to 1.
240+
obj->uart->CFG &= ~(1 << 0);
241+
242+
obj->uart->CFG = (1 << 0) // this will enable the usart
243+
| (data_bits << 2)
234244
| (paritysel << 4)
235245
| (stop_bits << 6);
236246
}

0 commit comments

Comments
 (0)