aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorUri Shaked2020-07-09 16:16:42 +0300
committerUri Shaked2020-07-09 16:16:42 +0300
commit5a8330c20db9ef1ee7fa555e40c16a58c81c860d (patch)
tree29d6d4954320215d56d14432541a86a80f3cc1e0 /src
parentfix(usart): TXC interrupt triggered incorrectly (diff)
downloadavr8js-5a8330c20db9ef1ee7fa555e40c16a58c81c860d.tar.gz
avr8js-5a8330c20db9ef1ee7fa555e40c16a58c81c860d.tar.bz2
avr8js-5a8330c20db9ef1ee7fa555e40c16a58c81c860d.zip
fix(usart): bitsPerChar looking at the wrong register
close #52
Diffstat (limited to 'src')
-rw-r--r--src/peripherals/usart.spec.ts15
-rw-r--r--src/peripherals/usart.ts2
2 files changed, 10 insertions, 7 deletions
diff --git a/src/peripherals/usart.spec.ts b/src/peripherals/usart.spec.ts
index 2f976ec..04e377b 100644
--- a/src/peripherals/usart.spec.ts
+++ b/src/peripherals/usart.spec.ts
@@ -10,7 +10,7 @@ const SREG = 95;
// USART0 Registers
const UCSR0A = 0xc0;
const UCSR0B = 0xc1;
-const UCSR0C = 0xc3;
+const UCSR0C = 0xc2;
const UBRR0L = 0xc4;
const UBRR0H = 0xc5;
const UDR0 = 0xc6;
@@ -26,6 +26,9 @@ const UDRE = 0x20;
// Interrupt address
const PC_INT_UDRE = 0x26;
const PC_INT_TXC = 0x28;
+const UCSZ0 = 2;
+const UCSZ1 = 4;
+const UCSZ2 = 4;
describe('USART', () => {
it('should correctly calculate the baudRate from UBRR', () => {
@@ -55,29 +58,29 @@ describe('USART', () => {
it('should return 6-bits per byte when UCSZ = 1', () => {
const cpu = new CPU(new Uint16Array(1024));
const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ);
- cpu.writeData(UCSR0A, 0x2);
+ cpu.writeData(UCSR0C, UCSZ0);
expect(usart.bitsPerChar).toEqual(6);
});
it('should return 7-bits per byte when UCSZ = 2', () => {
const cpu = new CPU(new Uint16Array(1024));
const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ);
- cpu.writeData(UCSR0A, 0x4);
+ cpu.writeData(UCSR0C, UCSZ1);
expect(usart.bitsPerChar).toEqual(7);
});
it('should return 8-bits per byte when UCSZ = 3', () => {
const cpu = new CPU(new Uint16Array(1024));
const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ);
- cpu.writeData(UCSR0A, 0x6);
+ cpu.writeData(UCSR0C, UCSZ0 | UCSZ1);
expect(usart.bitsPerChar).toEqual(8);
});
it('should return 9-bits per byte when UCSZ = 7', () => {
const cpu = new CPU(new Uint16Array(1024));
const usart = new AVRUSART(cpu, usart0Config, FREQ_16MHZ);
- cpu.writeData(UCSR0A, 0x6);
- cpu.writeData(UCSR0B, 0x4);
+ cpu.writeData(UCSR0C, UCSZ0 | UCSZ1);
+ cpu.writeData(UCSR0B, UCSZ2);
expect(usart.bitsPerChar).toEqual(9);
});
diff --git a/src/peripherals/usart.ts b/src/peripherals/usart.ts
index eb6171e..16d86f8 100644
--- a/src/peripherals/usart.ts
+++ b/src/peripherals/usart.ts
@@ -115,7 +115,7 @@ export class AVRUSART {
get bitsPerChar() {
const ucsz =
- ((this.cpu.data[this.config.UCSRA] & (UCSRC_UCSZ1 | UCSRC_UCSZ0)) >> 1) |
+ ((this.cpu.data[this.config.UCSRC] & (UCSRC_UCSZ1 | UCSRC_UCSZ0)) >> 1) |
(this.cpu.data[this.config.UCSRB] & UCSRB_UCSZ2);
switch (ucsz) {
case 0:
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.