Page 46
Change
This uses the same CmakeLists.txt file as blinky in the previous chapter and the same launch.json file. The only difference is that now we are using GP22.
to
This uses the same CMakeLists.txt file as blinky in the previous chapter and the same launch.json file. The only difference is that now we are using GP22.
i.e. change m to M
Page 61
As the internal pull-down resistor is used, the switch can be connected to the line and ground without any external resistors:
should read:
As the internal pull-up resistor is used, the switch can be connected to the line and ground without any external resistors:
Page 131
The line in the first new paragraph:
The PWM output in this configuration mimics the workings of an 8-bit A-to-D converter.
shoudl read:
The PWM output in this configuration mimics the workings of an 8-bit D-to-A converter.
i.e. swap A and D.
Page 135
The graph axis labels need to be switched.
Page 167
So for example, if we use GP28 as the first GPIO line the four lines are GP18, GP19, GP20 and GP21 and the first element of stepTable sets just GP21 to high.
should read
So for example, if we use GP18 as the first GPIO line the four lines are GP18, GP19, GP20 and GP21 and the first element of stepTable sets just GP21 to high.
i.e. change GP28 to GP18
Page 171
the rotation is in rotations per second not per minute - I forgot to multiply by 60.
It should read:
In this case, H‑bridge GP21 is A, GP20 is B, GP19 is A- and GP18 is B-. The stepping speed is such that a 200-step motor, i.e. 400 half steps, will rotate in 400*1 ms= 0.4 s, i.e. 2.5 rps (revolutions per second), which is a good starting speed. Decrease the sleep time for a higher speed.
The error is also on:
Page 173
Notice that we have to deal with the case of speed set to zero separately to avoid a divide by zero exception. The speed is specified in rps *100. So setting speed to 250 gives a rotation of 2.5rps.
Page 187
Next we can send some data and receive it right back:
uint8_t read_data = bcm2835_spi_transfer(0xAA);
remove the program line and change the : to ;
Next we can send some data and receive it right back.
Page 188
If you connect a logic analyzer to the three pins involved – 4, 6 and 7, you will see the data transfer:
change to:
If you connect a logic analyzer to the three GPIO lines involved – 4, 6 and 7, you will see the data transfer:
i.e change pins to GPIO lines
Page 229
Temperature in °C= -46.85 + 175.72 * data16 / 216
change to
Temperature in °C= -46.85 + 175.72 * data16 / 216
change 216 to 216
Page 230
RH= -6 + 125 * data16 / 216
change to
RH= -6 + 125 * data16 / 216
change 216 to 216
Page 243
You can use the registers to implement a for loop with up to 32 repeats. The jmp instruction can test the value of a register for zero and auto-decrement it after the test. This means an n repeat for loop can be constructed as:
set x,n loop: nop jump x--, loop
Using this you can slow the rate at which the GPIO line is toggled by repeating the nop 32 times. However, even if you use:
set x,n loop: nop [31] jump x--, loop
the effective rate of toggling the GPIO line is still too great to see an LED flash. To slow it down even more you need two nested loops.
change to
You can use the registers to implement a for loop with up to 32 repeats. The jmp instruction can test the value of a register for zero and auto-decrement it after the test. This means an n repeat for loop can be constructed as:
set x,n loop: nop jmp x--, loop
Using this you can slow the rate at which the GPIO line is toggled by repeating the nop 32 times. However, even if you use:
set x,n loop: nop [31] jmp x--, loop
the effective rate of toggling the GPIO line is still too great to see an LED flash. To slow it down even more you need two nested loops.
i.e. change jump to jmp
Page 247
This seems simple, but the set pindir is more complicated than you might expect. The set instruction sets the direction of the SET group of pins. The literal value used in the instruction is used as a mask to set the pin directions. This means that it can only set the direction of the first five GPIO lines in the SET group. This usually isn’t a problem as using more than five GPIO lines for output is uncommon. However, the out instruction sends the data from the OSR to the first two GPIO lines in the OUT group, not the SET group. You can see that the set instruction only enables the first two lines of the OUT group if they are the same in both groups.
change to
This seems simple, but the set pindirs is more complicated than you might expect. The set instruction sets the direction of the SET group of pins. The literal value used in the instruction is used as a mask to set the pin directions. This means that it can only set the direction of the first five GPIO lines in the SET group. This usually isn’t a problem as using more than five GPIO lines for output is uncommon. However, the out instruction sends the data from the OSR to the first two GPIO lines in the OUT group, not the SET group. You can see that the set instruction only enables the first two lines of the OUT group if they are the same in both groups.
i.e. pindir -> pindirs
Page 253
sm_config_set_sideset_pins(&c,2); pio_gpio_init(pio0, 2); pio_gpio_init(pio0, 3);
The first instruction has to be changed to:
pio_sm_set_consecutive_
Page 336
int getBlocks(uint8_t buf[], int len, int num, char target[])
{
for (int i = 0; i < num; i++)
{ if (uart_is_readable_within_us(uart1, 1000 * 1000));
getBlock(buf, len);
if (strstr(buf, target))
return i;
}
return -1;
}
change to:
int getBlocks(uint8_t buf[], int len, int num, char target[])
{
for (int i = 0; i < num; i++)
{ if (uart_is_readable_within_us(uart1, 1000 * 1000))
{
getBlock(buf, len);
if (strstr(buf, target))
return i;
}
}
return -1;
}
i.e. add {} around if body.