I use either a small electric coffee bean grinder (the kind with the spinning blades) which I've dedicated to spices or, if I'm grinding a large quantity a burr grinder. Most spices I briefly toast first, cool, then grind.
Ive only grinded black pepper but I just use my everyday coffee grinder. Before I start I throw in some uncooked rice and grind it. This cleans the entire inside of the grinder spotless. Then I grind the pepper, or whatever spice you want, then repeat the rice step. Never get a hint of either the coffee or the spices.
Everyone I know who grinds has a dedicated spice grinder b/c of the flavor left in. So rice cleans it out, huh? I'll have to pass the little bit of info on. Thanks